简体   繁体   中英

find the signed minimum value in a three dimensional matrix in MATLAB

I have a 3D matrix d and I want to find the signed minimum value along the third dimension. Currently, I use following code

tmp = abs(d);
[row, col]=ndgrid(1:size(d,1),1:size(d,2));

[v,ind] = min(tmp,[],3); 
index = row + size(d,1)*size(d,2)*(ind-1)+ size(d,1)*(col-1); %turn the ind to index
dm = d(index); %get the signed minimum value

The above code does not so efficient. Does anyone know a better choice? Thank you!

无需创建rowcol值的网格以将ind转换为可用于索引回d索引,您只需使用min第一个输出即可,输出包含第三个维度上的最小值。

dm = min(abs(d), [], 3);

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