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!
无需创建row
和col
值的网格以将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.