how to solv this issue?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
LastName = {'Sanchez';'Johnson';'Li';'Diaz'};
Age = [38;43;38;40];
Smoker = logical([1;0;1;0]);
Height = [71;69;64;67];
Weight = [176;163;131;119];
BloodPressure = [93; 77; 83;80];
BP=[125;135;146;150]
T = table(LastName,Age,Smoker,Height,Weight,BloodPressure,BP)
T1=table2cell(T)
T2=T1(:,2:5)
for i=1:4
for j=1:4
properties=T2(i,j);
end
temp1=T2(i,1);
temp2=T2(i,2);
temp3=T2(i,3);
temp4=T2(i,4);
temp5=T2(i,5);
create(temp1,temp2,temp3,temp4,temp5)
end
function create(temp1,temp2,temp3,temp4,temp5) % now i explained in detail my code
disp('age is')
disp(temp1)
if height==0
disp(temp4)
elseif height==1
disp(temp5)
end
end
% % error index in posiotion exceeds array bounds index must not exceeds 4
% R = [25;50;100;250] This is part of my program which i have tried
% to explain in simple way
% L=10
% A=5
% for i=1:4
% res=R(i)
% resistivity(R,A,L)
% end
%
% function resistivity(R,A,L)
% Rho=(R*L)/A
% end
i am getting an error index exceeds array bounds
how to rectify this error?
2 Kommentare
Akzeptierte Antwort
Voss
am 12 Apr. 2022
The error happens on this line:
temp5=T2(i,5);
and is caused by attempting to access an element in column 5 of T2 but T2 has only 4 columns
LastName = {'Sanchez';'Johnson';'Li';'Diaz'};
Age = [38;43;38;40];
Smoker = logical([1;0;1;0]);
Height = [71;69;64;67];
Weight = [176;163;131;119];
BloodPressure = [93; 77; 83;80];
BP=[125;135;146;150];
T = table(LastName,Age,Smoker,Height,Weight,BloodPressure,BP)
T1=table2cell(T)
T2=T1(:,2:5) % columns 2 through 5 of T1 means that T2 has 4 columns
for i=1:4
temp1=T2(i,1);
temp2=T2(i,2);
temp3=T2(i,3);
temp4=T2(i,4);
temp5=T2(i,5); % error here: T2 has only 4 columns
create(temp1,temp2,temp3,temp4,temp5)
end
function create(temp1,temp2,temp3,temp4,temp5)
disp('age is')
disp(temp1)
if height==0
disp(temp4)
elseif height==1
disp(temp5)
end
end
I don't know the correct way to rectify this error since I don't know what the code is supposed to do, but perhaps T2 should be defined differently. Maybe this:
T2=T1(:,2:6) % 5 columns
or maybe this:
T2=T1(:,2:end) % all columns from T1 except the first one
0 Kommentare
Weitere Antworten (0)
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!