How to retrieve multiple values from a 3D array

조회 수: 1 (최근 30일)
mustafa ozendi
mustafa ozendi 2021년 5월 6일
답변: dpb 2021년 5월 6일
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에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by