matlab plot 错误,Matlab中的绘图错误(Plotting Error in Matlab)

Matlab中的绘图错误(Plotting Error in Matlab)

将matlab图打印成PDF时遇到问题。 在研究了几个小时的解决方案之后,我一直无法找到解决方案。 我一直收到相同的错误消息。 我感谢您的帮助。

x = [2 4 7 2 4 5 2 5 1 4];

fig=plot(x);

print(fig,'-dpdf')

Error using

checkArgsForHandleToPrint>LocalCheckHandles

(line 88)

MATLAB Graphics handle must be a figure.

Error in checkArgsForHandleToPrint (line 30)

Error in print>LocalCreatePrintJob (line 336)

handles = checkArgsForHandleToPrint(0,

varargin{:});

Error in print (line 153)

[pj, inputargs] =

LocalCreatePrintJob(varargin{:});

Having an issue with printing my matlab plots into a PDF. After researching for a solution for several hours I have been unable to find a solution. I keep getting the same error message. I appreciate your help.

x = [2 4 7 2 4 5 2 5 1 4];

fig=plot(x);

print(fig,'-dpdf')

Error using

checkArgsForHandleToPrint>LocalCheckHandles

(line 88)

MATLAB Graphics handle must be a figure.

Error in checkArgsForHandleToPrint (line 30)

Error in print>LocalCreatePrintJob (line 336)

handles = checkArgsForHandleToPrint(0,

varargin{:});

Error in print (line 153)

[pj, inputargs] =

LocalCreatePrintJob(varargin{:});

原文:https://stackoverflow.com/questions/39839165

更新时间:2020-02-01 08:24

最满意答案

plot返回'Line'类型的图形对象的句柄,该图形对象至少比'Figure'低两级。 但是print函数需要一个数字(如错误信息所示)。

设置fig=gcf而不是将其设置为plot()的输出。 这代表“获得当前数字”。 或者,你可以利用这样的约定,至少在默认情况下,图形句柄等于你在图标题栏中看到的整数 - 所以如果你想打印图1,你可以说print(1, '-dpdf')

plot returns the handle to a graphics object of type 'Line' which is at least two levels below 'Figure'. But the print function expects a figure (as the error message says).

Set fig=gcf instead of setting it to the output of plot(). That stands for "get current figure". Alternatively, you can take advantage of the convention that, at least by default, figure handles are equal to the integer numbers that you see in the figure title bars—so if you want to print figure 1, you could say print(1, '-dpdf')

2016-10-03

相关问答

将您的代码更改为: t = 0:0.002:5;

k = [2; 4; 6; 8];

i = (1/pi) + 0.5*sin(4*t)

for j=1:4

i = i-(2/pi)*((cos(4*k(j)*t))/(k(j)*k(j)-1));

end

plot(t,i)

原因是k是col-vector(或4x1矩阵),所以你不能简单地将它乘以k*k 。 对于矩阵乘法,左右的大小必须遵循n × m和m × p 。 在这种情况下,您需要循环乘以k每个元素。 Change your c

...

本MathWorks技术说明中介绍了一些更常见的部分。 Some of the more common ones are explained in this MathWorks Technical Note.

好的,我不确定为什么会这样,但我稍微改变了代码顺序: figure

plot(datee,[allfile.bytes],'k','LineWidth',1.5);

hold on;

plot(datee,EMA,'--b','LineWidth',0.75);

title(sprintf('File size of %s',[token{1},dateno{1},name]));

xlimit = get(gca,'XLim');

...

您正在绘制一个包含大量零的向量。 因此绘制的线结束于(0,0,0)。 不要试图绘制零点: plot3(y(1,1:i+1),y(2,,1:i+1),y(3,,1:i+1));

You are plotting a vector that contains lots of zeros. Thus the line plotted ends at (0,0,0). Try not plotting the zeros: plot3(y(1,1:i+1),y(2,,1:i+1),y(3,,1:i+1)

...

要在同一图上绘制多个矩阵,每个矩阵必须具有相同的尺寸。 在我们有两个465 X 1矩阵,两个1000 X 1矩阵和两个2500 X 1矩阵的情况下,所有矩阵的尺寸必须为2500 X 1。 要增加较小矩阵的尺寸,请将矩阵重新定义为该大小,并将空单元格设置为零。 这是通过以下代码完成的: matlab_t(2500,1)=0;

matlab_v(2500,1)=0;

ltspice_t(2500,1)=0;

ltspice_v(2500,1)=0;

完整代码使用修复: clear;

clc;

%%

...

你的情节大小是正确的。 位于基频处的脉冲的幅度来自余弦波的尺度,并除以2: 0.001 / 2 = 5e-4 。 这是因为cos函数可以使用Euler公式表示,使得它是两个复数指数的组合,它们都缩放了一半。 资料来源: 维基百科 因此,在期望频率处的复指数的傅立叶变换是单位长度脉冲(即,幅度是1)。 余弦波可以表示为以基频的正负版为中心的两个复指数。 由于欧拉公式,我们进一步缩放1/2 ,傅里叶变换具有线性特性,脉冲额外缩小1/2 。 您的余弦波还有一个额外的缩放因子,它可以再次缩放脉冲。 标度的

...

感谢您的帮助,但我无法实现任何代码或命令来获得答案。 与其说我很幸运,我发现了一个例子,MATLAB命令如下: x=linspace(0,5,3000);

y=(0*x).*(x<1) + (2*(x.^2)-(4.*x)+3).*((1<=x) & (x<2))

+ (cos(x)).*(2<=x);

plot(x,y, '.'), grid

axis([0 5 -2 4])

title ('Plot of f(t)'), xlabel('t'), ylabel('f(t)')

thanks

...

你得到了这个错误,因为你想要逐个元素乘法( .* )时使用矩阵乘法( .* )。 即使改变了,你的代码也是不完整的,因为x和y是向量。 您可能想要计算值数组的函数。 这可以使用meshgrid完成。 这里有更多信息。 x = -100 : 1 : 100;

y = -100 : 1 : 100;

[X,Y] = meshgrid(x,y);

A = (power(X, 2)+ power(Y, 2));

B = 50 * A;

C = sin(power(B,0.1));

z = (power(A

...

你需要有./运算符而不是/当按元素分割两个向量时。 试试这个 x = 0:0.05:1;

y = sqrt((abs(sin(21*pi*x)))./(2+sin(20*pi*x)));

plot(x,y)

you need to have the ./ operator instead of / when dividing two vectors element by element. Try this instead x = 0:0.05:1;

y = sqrt((abs(sin(21*pi

...

plot返回'Line'类型的图形对象的句柄,该图形对象至少比'Figure'低两级。 但是print函数需要一个数字(如错误信息所示)。 设置fig=gcf而不是将其设置为plot()的输出。 这代表“获得当前数字”。 或者,你可以利用这样的约定,至少在默认情况下,图形句柄等于你在图标题栏中看到的整数 - 所以如果你想打印图1,你可以说print(1, '-dpdf') plot returns the handle to a graphics object of type 'Line' whi

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值