Index exceeds the number of array elements. Index must not exceed 1.
6 次查看(过去 30 天)
显示 更早的评论
clc
clear
close all
spn=3; %subplot number
spnc=1;
%Coefficient for Force equations
%Air
Cr=0.12; %drag coefficient of rider
rho=1.168; %density of air (1.256 kg/m^3)
A=1.6; %projected area of the bike and rider(m^2)
%Bump
Pb=12; %bump power loss coef
%Rolling
Croll=0.08; %Coef or rolling resistance (should be 0.008)
%slope
g=9.81; %m/s^2
%load data
my_data=readmatrix('tt_rider01.xlsx');
Mrider= 163.2 * 0.4536; %convert from lbs to kg
lat=my_data(:,1);
lon=my_data(:,2);
elev=my_data(:,3);
dist=my_data(:,4);
V=my_data(:,6);
subplot(spn,spnc,1)
geoplot(lat,lon)
subplot(spn,spnc,2)
plot(dist,V)
%
for ii=2:length(dist)
Ddist(ii)=dist(ii)-dist(ii-1);
VA(ii)=(V(ii)+V(ii-1))/2;
DV(ii)=V(ii)-V(ii-1);
Delev(ii)=elev(ii)-elev(ii-1);
if VA(ii)<=0
VA(ii)=0.1;
end
end
Ddist(1)=0.1;
VA(1)=.1;
%Delev(0)=0:.1;
%calculate time steps
for ii=2:length(dist)
dt(ii)=Ddist(ii)/VA(ii);
Acc(ii)=DV(ii)/dt(ii);
end
subplot(spn,spnc,3)
plot(Acc)
title('Acceleration')
%Slope angle calculations (in degrees)
for ii=2:length(dist)
slope(ii)=atand(Delev(ii)/Ddist(ii));
end
subplot(spn,spnc,3)
plot(slope)
%Force calculations
for ii=1:length(dist)
Fslope(ii)=Mrider*g*sind(ii);
Fbump(ii)=Pb(ii)/VA(ii); %this line of code is givig me the error
Froll(ii)=Croll*Mrider*g*cosd(slope(ii));
Fair(ii)=Cr*A*rho*VA(ii)^2;
Frider(ii)=Mrider*Acc(ii)+Fslope(ii)+Fbump(ii)+Froll(ii)+Fair(ii);
Prider(ii)=Frider(ii)*VA(ii);
end
subplot(spn,spnc,5)
plot(Fslope)
title('Fslope')
0 个评论
回答(2 个)
Torsten
2022-11-28
Pb is a scalar. So Pb(ii) does not exist.
You can use
Fbump(ii)=Pb/VA(ii); %this line of code is givig me the error
but I don't know that this is what you want.
0 个评论
chrisw23
2022-11-28
use a try catch block to debug
...
try
Fbump(ii)=Pb(ii)/VA(ii); %this line of code is givig me the error
catch ex
disp(ex.message) % breakpoint here and debug your variables and indices
end
...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!