Asked by alexr
on 2 May 2011

I have googled this to death, the common error was people looping arrays. I just have 2 simple sets and cant see where the error is.

simulated=[0.0000000 4.3830000 4.9470000 2.0180000 0.1761000 0.0162800 4.3650000 4.9540000 2.0170000 0.1760000 0.0162700 ]

actual= [0.0750000 4.0750000 4.7630000 3.5130000 0.5125000 0.1375000 2.6380000 4.5750000 4.8880000 1.5130000 0.3250000 ]

x = 0:0.0002:0.01;

plot(x, simulated, x, actual);

legend('Simulated', 'Actual')

ylabel('Current (mA)')

xlabel('Time ( mS )')

title('Current across R2 as a function of VS','FontSize',12)

Answer by Smith
on 30 Oct 2016

You just need to modify variable x to match the size of variable simulated or variable actual.

simulated=[0.0000000 4.3830000 4.9470000 2.0180000 0.1761000 0.0162800 4.3650000 4.9540000 2.0170000 0.1760000 0.0162700 ]

actual= [0.0750000 4.0750000 4.7630000 3.5130000 0.5125000 0.1375000 2.6380000 4.5750000 4.8880000 1.5130000 0.3250000 ]

x = linspace(0,0.01,length(actual));

plot(x, simulated, x, actual);

legend('Simulated', 'Actual')

ylabel('Current (mA)')

xlabel('Time ( mS )')

title('Current across R2 as a function of VS','FontSize',12)

assiya malik
on 14 Nov 2016

i am getting the same error i used linspace command still i coundnt remove the error my code contains

y =1.3:h:-1.3; % Calculates upto y(1)

u = zeros(1,length(y));

v = zeros(1,length(y));

w = zeros(1,length(y));

z = zeros(1,length(y));

after this i calculated u , v , w, z by Runge Kutta 4 method finally when i plotted using

plot(y,z,'y--',y,w,'g--',y,v,'r',y,u,'b--');

i got the same error

Jan
on 14 Nov 2016

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Paulo Silva (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/6670-vectors-must-be-the-same-lengths-plotting#comment_13754

## Andrew Newell (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/6670-vectors-must-be-the-same-lengths-plotting#comment_13756

## alexr (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/6670-vectors-must-be-the-same-lengths-plotting#comment_13767

## waqas muhammad (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/6670-vectors-must-be-the-same-lengths-plotting#comment_525137

Sign in to comment.