Index Exceeds Number of Array Elements Error in For Loop

조회 수: 2 (최근 30일)
N/A
N/A 2020년 10월 6일
댓글: N/A 2020년 10월 6일
I keep receiving the following error on line 36 (Icom2=....): Index exceeds the number of array elements (1). I am unsure what is wrong as I have tried everything I can think of to resolve the issue.
%William D. - ME411 HWK4 - October 4, 2020
load trial1.txt
M=86; %Total Body Mass is 85kg
x1=trial1(:,1);
x2=trial1(:,3);
y1=trial1(:,2);
y2=trial1(:,4);
fs=100;
t=[1/fs:1/fs:length(trial1)/fs];
plot(t,trial1)
xlabel('Time')
ylabel('Position')
title('Trial Data')
%>>>>Combined Foot and Leg Mass<<<<
footandlegM=0.061*M;
fprintf('Combined foot and leg Mass=')
disp(footandlegM)
%>>>>Center of Mass for Combined Foot and Leg<<<<<
for i=1:length(trial1)
Lo(i)=sqrt((x1(i)-x2(i))^2+(y1(i)-y2(i))^2);
end
L=mean(Lo);
COMp=0.606*L; %Nearest Proximal
COMd=0.394*L; %Nearest Distal
fprintf('COMproximal=')
disp(COMp)
fprintf('COMdistal=')
disp(COMd)
%>>>>>Moment of Intertia - about COM<<<<<
COG=0.416*L;
Icom=(footandlegM)*COG^2;
fprintf('Icom=')
disp(Icom)
for k=1:length(Lo) %Varying With Time
COG2(k)=0.416*Lo(k);
Icom2(k)=(footandlegM)*COG(k)^2
end
%>>>>>Moment of Intertia - about knee<<<<<
P=0.735*L;
Ip=footandlegM*P^2; %Proximal Radius of Gyration
%for j=1:length(Lo)
% for c=1:length(Lo)
% PII=0.735*Lo(c);
%end
%IIp(j)=footandlegM.*(PII(j)).^2; %Inertia with time
%end
Iu=Icom+(COMp^2)*(footandlegM); %Parallel Axis Theorem
fprintf('Ip=')
disp(Ip)
fprintf('Iparallelaxis=')
disp(Iu)
%>>>>>Time and Inertia Value<<<<<
%Nobody Cares, Work Harder
%Keep Hammering

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 6일
COG=0.416*L;
GOC is a scalar.
for k=1:length(Lo) %Varying With Time
COG2(k)=0.416*Lo(k);
Icom2(k)=(footandlegM)*COG(k)^2
end
You assign to COG2(k) in the one line. In the next line you try to index COG(k) rather than the COG2(k) that you just wrote to. But COG is a scalar.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by