How do I refer to values that contain decimal points and integers (for example, 1.0000 ... and 1)?
2 views (last 30 days)
Show older comments
I want to take out the row in which the first column of the cell array b (above image) is 1 (including 1.0000) and put it into the cell array a.
When I wrote the code like this, I can only get the integer 1.
a = b(cellfun(@(x) x == 1, b(:,1)),:);
How do I get 1.0000 rows too?
1 Comment
Stephen23
on 22 Sep 2021
Edited: Stephen23
on 22 Sep 2021
"I want to take out the row in which the first column of the cell array b (above image) is 1 (including 1.0000)"
Your code matches values exactly equal to one (as indicated by "1").
But "1.0000" indicates a value that it is not exactly one.
If you want to include vaues that are not quite equal to one (such as those indicated by "1.0000") then you will have to include a tolerance in your value comparison. You will have to decide how much tolerance is acceptable.
A more efficient approach than CELLFUN:
tol = 1e-10;
idx = [b{:,1}] < tol;
out = b(idx,;)
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!