# How to make the following code valid for tables not only matrices

조회 수: 1(최근 30일)
Salma fathi 2022년 6월 22일
답변: Eric Sofen 2022년 6월 23일
hello, The following code finds the peak point for some data stored in an array or matrix lets say.
for ied=1:length(EDP)
imax=[];
[~,imax] = max(EDP(:,7)); %column 7 we have the variable NE8 which we are intrested in finding its maximum
if (EDP(imax,6) < 190 || EDP(imax,6) >400) %column 6 we have the variable GDALT, which is the alttitued
EDP(imax,:)=[];
elseif ( EDP(imax,6) > 190 && EDP(imax,6) < 190) %the range for the altitude of the peak is between 190-400
break;
end
end
How can we modify it such that it would be valid for data that are stored in tables also not only arrays or matrices.

댓글을 달려면 로그인하십시오.

### 답변(2개)

KSSV 2022년 6월 22일
Convert the Table into array using table2array. You can extract any column from table T using T.(1), T.(2) etc....
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
KSSV 2022년 6월 22일
You can access any column of the table, I have already mentioned it.

댓글을 달려면 로그인하십시오.

Eric Sofen 2022년 6월 23일
There are a few ways to rework the indexing to work with tables. By the way, I'm not sure what the loop does (ied doesn't appear in the body of the loop).
[~,imax] = max(EDP.NE8); %column 7 we have the variable NE8 which we are intrested in finding its maximum
if (EDP.GDALT(imax) < 190 || EDP.GDALT(imax) >400) %column 6 we have the variable GDALT, which is the alttitued
EDP(imax,:)=[];
elseif ( EDP.GDALT(imax) > 190 && EDP.GDALT(imax) < 190) %the range for the altitude of the peak is between 190-400
break;
end

댓글을 달려면 로그인하십시오.

### 범주

Find more on Matrix Indexing in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!