Delete row from cell array if the difference between two cells is greater then X
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Guillaume
2016-7-5
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 个评论
Thorsten
2016-7-5
And to actually delete the row, use
JFM06CS(rowToDelete,:) = [];
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!