[英]MATLAB List values above threshold
I have a 3D matrix. 我有一个3D矩阵。 I can use the below code to find the number of elements above 1.61. 我可以使用下面的代码来查找1.61以上的元素数量。 How can I actually list the elements that are above 1.61 and show what value they are? 我怎样才能真正列出1.61以上的元素并显示它们的价值? for instance, if I have a value of 8.1 and 9.1, I would like Matlab to tell me those two values. 例如,如果我的值为8.1和9.1,我希望Matlab告诉我这两个值。 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: 如果要获取3D阵列B
每个第三索引层的结果,可以使用单元格进行:
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. 然后result{1}
给出对应于B(:,:,1)
等的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.