Extracting Matrix/Matrices from a 4D Matrix
12 ビュー (過去 30 日間)
古いコメントを表示
Amine Ben Ayara
2016 年 10 月 17 日
コメント済み: Walter Roberson
2016 年 10 月 18 日
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!