Matrix into Sub matrix of length 8
1 回表示 (過去 30 日間)
古いコメントを表示
Suppose I have a matrix like this A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24] (Length of a Matrix is always multiple of 8). I want to break it into sub matrices of length 8. I use reshape function but it does not work. Needs your help.
1 件のコメント
dpb
2019 年 5 月 5 日
What does "does not work" mean, precisely? Show your work, error received...or what you expected instead.
In general breaking into submatrices by creating new variables isn't productive manner in which to use, Matlab; instead reference subsets of an array as needed for which reshape can be quite useful...or, depending on what it is that is actually being done, blockproc in the image processing toolbox can be the ticket or various other specialty routines can be the answer--each depending on just what the actual end need may be...
採用された回答
Image Analyst
2019 年 5 月 5 日
What did you try for reshape? Did you try reshape(A, [], 8)?
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
a8 = reshape(A, [], 8)
% For example, to get 2nd subarray of 8 specify group as 1st index and : as second index.
out = a8(2,:)
その他の回答 (1 件)
KALYAN ACHARJYA
2019 年 5 月 5 日
編集済み: madhan ravi
2019 年 5 月 5 日
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
n=length(A)/8;
C=num2cell(reshape(A,length(A)/n,n),1);
Access the subarrays in C{1}, C(2)..so on..
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!