我不明白出现以下错误的原因是什么?这里给出了代码
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);
代码中似乎一切正常,但为什么会出现以下错误?你能帮我吗?编辑:
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
Error using plot
Vectors must be the same lengths.
Error in subplot1 (line 10)
plot(x,squared);