Reputation: 342
I have a 3D matrix. I can use the below code to find the number of elements above 1.61. How can I actually list the elements that are above 1.61 and show what value they are? for instance, if I have a value of 8.1 and 9.1, I would like Matlab to tell me those two values. Can I do that?
for i = 1:5
A = ans.atom_data(:,5,i);
count(i,:) = sum(A(:)>1.61)
end
Upvotes: 0
Views: 538
Reputation: 112659
If you only want to know the values, use logical indexing, like this:
result = A(A>1.61);
If you want to obtain the result for each third-index-layer of a 3D array B
, you can do it with cells:
result = cellfun(@(x) x(x>1.61), squeeze(mat2cell(B,size(B,1),size(B,2),ones(1,size(B,3)))),'uni',0);
Then result{1}
gives the values corresponding to B(:,:,1)
, etc.
Upvotes: 2