How do I efficiently remove unwanted data points from a complex data structure?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
HRmatlab
am 7 Jan. 2016
Kommentiert: HRmatlab
am 7 Jan. 2016
I have a fairly complex structure S containing data with multiple fields (more than 40). Some of the structure fields are simple vector arrays (Nx1) but many are 2D arrays (NxM). I need to filter the data based on fairly simple criteria (e.g. if S.field1 > 1 or S.field5 == 0 etc.). When I use a loop to go through all N rows of the structure it is painfully slow (N can be > 100,000). Is there a more efficient way to do this, especially for the NxM fields? Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Jan. 2016
mask = S.field1 > 1;
new_S = structfun(@(F) F(mask,:), S, 'Uniform', 0);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!