How to retrieve multiple values from a 3D array

11 次查看(过去 30 天)
Dear All,
I have a 3D matrix
I_dd (212x210x245)
and a 2D matrix
occupied_box_indices(4x3) = [156 151 34
156 151 33
156 150 33
177 74 5]
I want to create a vector using these matrcies as below:
I_adress_boxes(1) = I_dd(occupied_box_indices(1,1),occupied_box_indices(1,2),occupied_box_indices(1,3));
I_adress_boxes(2) = I_dd(occupied_box_indices(2,1),occupied_box_indices(2,2),occupied_box_indices(2,3));
I_adress_boxes(3) = I_dd(occupied_box_indices(3,1),occupied_box_indices(3,2),occupied_box_indices(3,3));
I_adress_boxes(4) = I_dd(occupied_box_indices(4,1),occupied_box_indices(4,2),occupied_box_indices(4,3));
With a for loop it can be done very easliy. However, I wonder if is it possible to cerate the I_adress_boxes without for loop and which way do you think is the best in terms of computation time?

采纳的回答

dpb
dpb 2021-5-6
Ignoring the excessively verbose variable names that keeps code from being visible without scrolling or breaking line and thereby harder to read to get matching parens right...
I_adress_boxes=I_dd(ind2sub(size(I_dd),occupied_box_indices(:,1), ...
occupied_box_indices(:,2), ...
occupied_box_indices(:,3)));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by