For Loop Indexing of matrices
2 ビュー (過去 30 日間)
古いコメントを表示
I have a matrix of dimensions 36x25x355.
I would like to extract 36x25 arrays from this data and index them 1,2,3 and so on, as descrtibed in attached picture. I would like to be able to do this for any size matrix multipe times so I need to create a for loop.
As 355 does not divide wholly into 25, I would like the last array to be smaller than the others.
Any help with this woud be greatly appreciated.

2 件のコメント
回答 (2 件)
Matt J
2021 年 3 月 9 日
編集済み: Matt J
2021 年 3 月 9 日
Using mat2tiles
it's as simple as,
A=mat2tiles(yourMatrix,[36,25])
9 件のコメント
Steven Lord
2021 年 3 月 10 日
From this additional information about what you're trying to do, splitting this matrix into cells in a cell array doesn't seem like the best option anymore. Pad your array with columns of missing data at the end until its width is a multiple of the width of the "blocks" you want to create, then reshape the data into a 3-dimensional array.
n = 7;
A = magic(n)
paddedA = [A, NaN(n, 1)]
B = reshape(paddedA, [n 4 2])
Now you can use the dim input argument to functions like sum and max to compute the sum or maximum in a specific dimension.
C = max(B, [], 3)
Matt J
2021 年 3 月 10 日
Would there be a way to calculate the max value for each point in the 36x25? For example, I would want the maximum value of the first point out of alll the reshaped matrices.
Yes, max, min, mean, median... Whatever you like:
max( reshape( yourMatrix(:,1:350), 36,25,[]) ,[],3 )
Jan
2021 年 3 月 9 日
X = rand(36, 355);
w = 25; % Width of the tiles
sX = size(X);
M = [repmat(w, 1, floor(sX(2) / w)), rem(sX(2), w)];
M = M(M ~= 0); % Crop last tile, if it is 0
C = mat2cell(X, sX(1), M)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!