error using plot:Vectors must be the same lengths

I get this error in the plot line.
V=20;
t_sim=0.02;
sample_distance=0.2;
ts=sample_distance/V;
step_time=1;
step_size=0.01;
collect_ts=ts*1;
t_plot=(0:collect_ts:t_sim);
figure(6);
plot(t_plot,simout(:,1));hold all;plot(x,y);grid on;
xlabel('Time (s)');ylabel('lateral position (m)');
>> size(t_plot)
ans =
1 3
>> size(simout)
ans =
21 71
Can anyone please tell the reason for this error and how to solve it.

4 Commenti

Adam
Adam il 19 Ago 2014
Modificato: Adam il 19 Ago 2014
It's impossible to say really how to solve it. The plot doesn't work because the things you are plotting are clearly not the same size, but your posted code gives no indication of what simout is.
I suspect your parameterisation of t_plot is wrong if it only gives you 3 values, but I couldn't possibly say which component of it is wrong.
Thank you. Could you please find my below comment and see if you can help me out.
I'm afraid I don't know anything about Simulink, but I would still suggest that if you think those two quantities should be able to be plotted against each other and if the simout variable is correct then you need to look at how you are defining t_plot.
If your min and max are absolutely correct then
t_plot = linspace( 0, t_sim, 21 )
would at least give you the right length of vector, but I can't say if that would be correct or not.
Thanks. I will check it out.

Accedi per commentare.

Risposte (1)

Kyle
Kyle il 19 Ago 2014
I tried to reproduce your error, but the variables "simout," "x," and "y" are undefined in your included code.
Vectors must be same lengths suggests your rows and columns are not the same for t_plot and simout. It looks like t_plot has 1 row and 3 columns, while simout has 21 rows and 71 columns.

5 Commenti

Thanks. This is the value for
x=[0,1,1,5];
y=[0,0,d,d];
d = 0.01;
Yes I understand that they have different size but how to rectify this?
what is simout?
simout is the output from the model to the workspace.
Since your simout is 71 columns, t_plot should be too. Are you sure you want to plot t_plot,simout on the same plot as x,y? I ask because the max for t_plot = t_sim = 0.02, while x max is 5. When plotted together you can't clearly see the t_plot,simout (see plots below). The following works as an example:
simout = 0.01*rand(1,71);
d = 0.01; x=[0,1,1,5]; y=[0,0,d,d];
t_sim=0.02;
sample_distance=0.2;
V=70; %changed
ts=t_sim/V; %changed
step_time=1;
step_size=0.01;
collect_ts=ts*1;
t_plot=(0:collect_ts:t_sim); %collect_ts (and ts) must equal t_sim/(71-1)
figure(6);
plot(t_plot,simout); grid on; hold all; plot(x,y);
xlabel('Time (s)');ylabel('lateral position (m)');
Although I didn't use the sample_distance variable at all.
This has given me some clue. Anyway thanks for your help.

Accedi per commentare.

Tag

Richiesto:

il 19 Ago 2014

Commentato:

il 20 Ago 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by