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
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.
Priya
2014년 8월 19일
Adam
2014년 8월 19일
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.
Priya
2014년 8월 19일
답변 (1개)
Kyle
2014년 8월 19일
0 개 추천
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
Priya
2014년 8월 19일
Kyle
2014년 8월 19일
what is simout?
Priya
2014년 8월 19일
Kyle
2014년 8월 20일
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.


Priya
2014년 8월 20일
카테고리
도움말 센터 및 File Exchange에서 Ground Truth Labeling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!