Delete row from cell array if the difference between two cells is greater then X
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
David du Preez
am 5 Jul. 2016
Kommentiert: Thorsten
am 5 Jul. 2016
I have a cell array JFM06CS(88x4). I want to delete the row if the difference between column 4 and 2 is greater than 6.5. Attached is the file and I tried the following code.
rowToDelete = [JFM06CS{:,4} - JFM06CS{:,2}] > 6.5;
0 Kommentare
Akzeptierte Antwort
Guillaume
am 5 Jul. 2016
You nearly got it right:
rowToDelete = [JFM06CS{:,4}] - [JFM06CS{:,2}] > 6.5;
I would transpose the output to get a column vector.
Alternatively:
rowToDelete = diff(cell2mat(JFM06CS(:, [2 4])) > 6.5;
1 Kommentar
Thorsten
am 5 Jul. 2016
And to actually delete the row, use
JFM06CS(rowToDelete,:) = [];
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!