简体   繁体   中英

MATLAB List values above threshold

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM