error using plot:Vectors must be the same lengths

조회 수: 2 (최근 30일)
Priya
Priya 2014년 8월 19일
댓글: Priya 2014년 8월 20일
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
Adam
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
Priya 2014년 8월 19일
Thanks. I will check it out.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kyle
Kyle 2014년 8월 19일
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
Kyle
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
Priya 2014년 8월 20일
This has given me some clue. Anyway thanks for your help.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by