Extracting Matrix/Matrices from a 4D Matrix
조회 수: 12 (최근 30일)
이전 댓글 표시
Hello Matlab Wizards, Hope everyone is doing well. I need some directions with the most efficient one to extract a matrix or numerous matrices ( 5 by 5 dimension each) from a 4-D Double matrix. This is what I have:
My final matrix, BIG, dimension is : 5 *5 * 14680 * 30 ( so basically 14680 of "5*5" matrices and 30 sets of those).
Suppose I want to extract Matrix A ;number 2941, then it is located in final matrix: A=BIG(:,:,2941,1:30);
is that correct?
Now what If I need to extract numerous matrices from Big, suppose matrix number 5891, 5907,5872, and 5883, so how do I do it taking in consideration that each (5*5) matrix has to be picked 30 times (1:30)?
I did this :
for i=1:30;
Matrix_A(:,:,2941,i)=BIG(:,:,2941,i);
end
I got some strange results ( like many empty 5*5).
Do you think I can stack the extracted matrices horizontally or vertically some how, because I will eventually need to get a specific vector from each (1:5,1) [a "5*1" vector from each extracted matrix).
Please let me know if anyone has a suggestion, and I will try to explain better if not clear. I greatly apprciate the help in advance! Kind Regards
댓글 수: 0
채택된 답변
Walter Roberson
2016년 10월 17일
which_to_extract = [2941, 5891, 5907,5872, 5883];
just_those = BIG(:, :, which_to_extract, :);
댓글 수: 4
Walter Roberson
2016년 10월 18일
reshape( BIG(:, 1, which_to_extract, :), [], size(BIG,4) )
or possibly
reshape( permute( BIG(:, 1, which_to_extract, :), [3 1 4 2]), [], size(BIG,4) )
the difference is the stacking order, whether it is to go "across" or "down" before you make the result into a column. You just happen to be working with size(BIG,2) equal to length(which_to_extract) so I have not been able to figure out which order you want. If you had 4 to extract instead of 5, would you want to make it 5 x 4 x 30 and then reshape that to (5*4) x 30 ? Or would you want it to be 4 x 5 x 30 and then reshape to (4*5) x 30 ? The number of elements is the same in each case but the order is not the same.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!