Probably there is a file named subplot in your workspace
use subplot for ploting multiple graph in matlab
Question
i can't understand what is reason for following error?here is given code
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');
and error says
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);
it seems everything ok in code, but why is following error?could you help me? EDITED:
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');
error:
subplot1
Error using plot
Vectors must be the same lengths.
Error in subplot1 (line 10)
plot(x,squared);
Solution
OTHER TIPS
As noted above, the first error most comes from your file C:\Users\D.Datuashvili\Desktop\subplot.m which shadows the Matlab default.
the second error comes from the fact that the length of array squared
is longer, probably because you changed it earlier.
just add the following line before your script and it will be fine
clear squared cube linear log-of sqrt_of
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow