How to retrieve multiple values from a 3D array
조회 수: 1 (최근 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?
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!