Index exceeds the number of array elements. Index must not exceed 1.

1 vue (au cours des 30 derniers jours)
George
George le 28 Nov 2022
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');
Error using readmatrix
Unable to find or open 'tt_rider01.xlsx'. Check the path and filename or file permissions.
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')

Réponses (2)

Torsten
Torsten le 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.

chrisw23
chrisw23 le 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
...

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by