error using plot vectors must be same length

조회 수: 3 (최근 30일)
Rachel Belanger
Rachel Belanger 2021년 3월 31일
댓글: Star Strider 2021년 3월 31일
% Specify the three inputs
V = [0:10:200]; % Vehicle speed (mph)
Ngear = 6; % Gear number
%Gear Ratio/Efficiency
gear_level = [1:6];
gear_ratio =[4.027 2.364 1.532 1.152 0.852 0.6677]; % [1st 2nd...]
%Final Drive
FD_ratio = 2.56; % Final drive ratio
%Tire
Rw = 0.25; % Tire radius = 0.25m
%Unit Conversion
rps_rpm = 30/pi; % rad/sec to rpm
mps_mph = 2.237; % m/s to mph
G_1= [14.16 14.37 14.57 14.77 14.98 15.35 15.89 16.52 17.15 17.7 18.13 18.45 18.7 18.9 19.09]
G_2= [8.383 8.454 8.525 8.595 8.666 8.737 8.808 8.878 9.003 9.162 9.361 9.572 9.798 10.02 10.2]
G_3= [5.556 5.586 5.617 5.647 5.677 5.708 5.738 5.769 5.799 5.829 5.86 5.89 5.94 6.011 6.08]
G_4= [4.178 4.195 4.212 4.229 4.246 4.264 4.281 4.298 4.315 4.332 4.35 4.367 4.384 4.401 4.418]
G_5= [3.096 3.105 3.115 3.124 3.134 3.143 3.153 3.162 3.171 3.181 3.19 3.2 3.209 3.218 3.228]
G_6= [2.421 2.427 2.433 2.439 2.445 2.45 2.456 2.462 2.468 2.473 2.479 2.485 2.491 2.496 2.502]
figure(1)
plot(V,G_1,'b')
xlim([0 210])
ylim([0 21])
hold on plot(V,G_2,'g')
**and by these "plot" commands it says error using plot vectors not same size**
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2021년 3월 31일
Rachel - V is a 1x21 array and G_1 is a 1x15 array, so the error message makes sense. Should the G_x arrays be of the same size as V?

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

채택된 답변

Star Strider
Star Strider 2021년 3월 31일
The ‘V’ vector needs to be defined differently.
One possibility is:
V = linspace(0, 200, numel(G_1)); % Vehicle speed (mph)
defined after the ‘G’ vectors, with the complete code now being:
Ngear = 6; % Gear number
%Gear Ratio/Efficiency
gear_level = [1:6];
gear_ratio =[4.027 2.364 1.532 1.152 0.852 0.6677]; % [1st 2nd...]
%Final Drive
FD_ratio = 2.56; % Final drive ratio
%Tire
Rw = 0.25; % Tire radius = 0.25m
%Unit Conversion
rps_rpm = 30/pi; % rad/sec to rpm
mps_mph = 2.237; % m/s to mph
G_1= [14.16 14.37 14.57 14.77 14.98 15.35 15.89 16.52 17.15 17.7 18.13 18.45 18.7 18.9 19.09];
G_2= [8.383 8.454 8.525 8.595 8.666 8.737 8.808 8.878 9.003 9.162 9.361 9.572 9.798 10.02 10.2];
G_3= [5.556 5.586 5.617 5.647 5.677 5.708 5.738 5.769 5.799 5.829 5.86 5.89 5.94 6.011 6.08];
G_4= [4.178 4.195 4.212 4.229 4.246 4.264 4.281 4.298 4.315 4.332 4.35 4.367 4.384 4.401 4.418];
G_5= [3.096 3.105 3.115 3.124 3.134 3.143 3.153 3.162 3.171 3.181 3.19 3.2 3.209 3.218 3.228];
G_6= [2.421 2.427 2.433 2.439 2.445 2.45 2.456 2.462 2.468 2.473 2.479 2.485 2.491 2.496 2.502];
V = linspace(0, 200, numel(G_1));; % Vehicle speed (mph)
figure(1)
plot(V,G_1,'b')
xlim([0 210])
ylim([0 21])
hold on
plot(V,G_2,'g')
plot(V,G_3,'c')
plot(V,G_4,'m')
plot(V,G_5,'k')
plot(V,G_2,'r')
hold off
.
  댓글 수: 2
Rachel Belanger
Rachel Belanger 2021년 3월 31일
wow thank you sooo much this fixed it!
Star Strider
Star Strider 2021년 3월 31일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tires and Vehicles에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by