error using plot:Vectors must be the same lengths
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Adam
am 19 Aug. 2014
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.
Antworten (1)
Kyle
am 19 Aug. 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 Kommentare
Kyle
am 20 Aug. 2014
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.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!