Index exceeds the number of array elements. Index must not exceed 1.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Torsten
am 28 Nov. 2022
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 Kommentare
chrisw23
am 28 Nov. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!