filtering data inside a table and storing multiple tables in one big table
Afficher commentaires plus anciens
i am trying to do the following
After reading some data files where each file contains data stored in a table.
- we find the maximum point for one of the variables (in the 6th column in the table) according to the following criterea.
for ied=1:length(EDP)
imax=[];
[~,imax] = max(EDP(:,6));
if EDP(imax,1) < 190 % the first column in the table is the height
EDP(imax,:)=[];
elseif EDP(imax,1) > 190
2.then we check the following two conditions for this maximum point:
- the latitude for this max value should be in the interval (-12-1.5,-12+1.5)
- the longitude for this max value should be in the interval (-76.8-3,-76.8+3)
where the latitude and longitude are the 2nd and 3rd column in the table. If these conditions are satisfied then we store all the tables that have the condition satisfied in one big table, if the conditions are not satisfied then we simply ignore this table and go to the next file to read
To do that I have tried the following using two if statement inside the above for loop but I am not sure if I am doing this corectly or if there is a more easier way in matlab other than an if statement
if EDP(imax,2)>(stnLat-1.5) && EDP(imax,2)<(stnLat+1.5)
fprintf('If statement is passed.\n')
if EDP(imax,3)>(StnLong-3) && EDP(imax,3)<(StnLong+3)
fprintf('If statement is again passed.\n')
fprintf('\n')
if ifile==3
EDPAll=EDP(:,:);
else
EDPAll=[EDPAll;EDP(:,:)];
end
end
else
fprintf('If statement is NOT passed.\n')
end
If anyone can help, thank you in advance
Réponse acceptée
Plus de réponses (1)
Hi!
'After reading some data files where each file contains data stored in a table' >> EDP has only one table !!
Assuming your original EDP has many files ( tables), try the below code:
clear ;
EDP = load (websave('EDP','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1071645/EDP.mat') ) ; %% I am assuming EDP.mat contain multiple tables
EDP = struct2cell(EDP) ;
whos %
StnLat = -12 ;
StnLong = -76.8 ;
EDPALL = [] ;
for ied = 1:length(EDP)
[~,imax] = max(EDP{ied}.EDP6);
if EDP{ied}.EDP1(imax) < 190
% EDP(imax,:) = []; I did not understand why this line of code is here!!
continue
else
condiLatLong = (EDP{ied}.EDP2(imax)>(StnLat-1.5) && EDP{ied}.EDP2(imax) <(StnLat+1.5)) ...
&& (EDP{ied}.EDP3(imax)>(StnLong-3) && EDP{ied}.EDP3(imax) < (StnLong+3)) ;
if condiLatLong
fprintf('If statement is passed.\n')
EDPALL = [EDPAll; EDP{ied}];
else
fprintf('If statement is NOT passed.\n')
end
end
end
Hope this helps
Catégories
En savoir plus sur Data Type Identification dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!