在matlab中使用子图绘制多图
我不明白以下错误的原因是什么?这里给出了代码在matlab中使用子图绘制多图,matlab,subplot,Matlab,Subplot,我不明白以下错误的原因是什么?这里给出了代码 for i=1:20 x(i) = i-10; squared(i) = x(i) ^ 2; cube(i) = x(i) ^ 3; linear(i) = x(i); log_of(i) = log(x(i)); sqrt_of(i) = sqrt(x(i)); end subplot(2,3,1); plot(x,squared);
for i=1:20
x(i) = i-10;
squared(i) = x(i) ^ 2;
cube(i) = x(i) ^ 3;
linear(i) = x(i);
log_of(i) = log(x(i));
sqrt_of(i) = sqrt(x(i));
end
subplot(2,3,1);
plot(x,squared);
title('square');
subplot(2,3,4);
plot(sqrt_of,cube);
title('sqrt');
subplot(2,3,5);
plot(linear,cube);
title('linear');
subplot(2,3,6);
plot(log_of,cube);
title('log');
subplot(2,3,3);
plot(x,cube);
title('cube');
错误说
subplot1
Attempt to execute SCRIPT subplot as a function:
C:\Users\D.Datuashvili\Desktop\subplot.m
Error in subplot1 (line 9)
subplot(2,3,1);
代码中似乎一切正常,但为什么会出现以下错误?您能帮助我吗?
编辑:
错误:
subplot1
Error using plot
Vectors must be the same lengths.
Error in subplot1 (line 10)
plot(x,squared);
可能在您的工作区中有一个名为subplot的文件可能在您的工作区中有一个名为subplot的文件如上所述,第一个错误大部分来自您的文件C:\Users\D.Datuashvili\Desktop\subplot.m,它隐藏了Matlab默认值 第二个错误是由于数组
平方的长度较长,可能是因为您之前更改了它
只需在脚本之前添加以下行,就可以了
clear squared cube linear log-of sqrt_of
如上所述,第一个错误大部分来自文件C:\Users\D.Datuashvili\Desktop\subplot.m,该文件隐藏了Matlab默认值
第二个错误是由于数组平方的长度较长,可能是因为您之前更改了它
只需在脚本之前添加以下行,就可以了
clear squared cube linear log-of sqrt_of
什么是C:\Users\D.Datuashvili\Desktop\subplot.m?是matlab自己的函数还是你的文件?我现在已经更改了目录,但每当我运行它时,它只会显示一个数字。它说向量应该是相同的长度,我做了一些更改,上传的nowx和平方数组有不同的长度,你可以尝试通过在m文件的开头添加clear all来清除这些变量。现在它工作了,非常感谢,所以在编写M文件时最好始终使用clear all?什么是C:\Users\D.Datuashvili\Desktop\subplot.M?是matlab自己的函数还是你的文件?我现在已经更改了目录,但每当我运行它时,它只会显示一个数字。它说向量应该是相同的长度,我做了一些更改,上传的nowx和平方数组有不同的长度,你可以尝试通过在m文件的开头添加clear all来清除这些变量。现在它工作了,非常感谢,所以在编写M文件时最好始终使用clear all?