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

1 次查看(过去 30 天)
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
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 个评论
Salma fathi
Salma fathi 2022-6-22
thank you for your reply. I have tried doing that and it worked.. but dealing with arrays is giving me sme hard time when trying to do further processing thats why I would like to have it all working for tables since all my data is stored into tables instead of every time converting from table to array. Would that be possible?

请先登录,再进行评论。


Eric Sofen
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

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by