フィルターのクリア

Concatenate multi dimensional matrix

9 ビュー (過去 30 日間)
David Ponce
David Ponce 2018 年 10 月 12 日
回答済み: Matt J 2018 年 10 月 12 日
I have a matrix which has these 3rd dimensions or pages. A(:,:,1), A(:,:,2), A(:,:,3)
Now, I wanted these three to be vertically concatenated. But i'm looking for an algorithm like in a for sentence for do it in large scale.
I know this: b = cat(1,a(:,:,i)) but i don't have the entire matrix in b because its override. Thank you.

採用された回答

Guillaume
Guillaume 2018 年 10 月 12 日
編集済み: Guillaume 2018 年 10 月 12 日
Your b = cat(1, a(:, :, i)) is incorrect and is just equivalent to b = a(:, :, i). If you were to use a loop you could do it like this:
b = [];
for i = 1:size(a, 3)
b = [b; a(:, :, 1)]; %which is cat(1, b, a(:, :, i))
end
This would be extremely innefficient and matlab's editor will warn you that you're resizing b on every iteration. The proper way to do it in matlab is:
b = reshape(permute(a, [1 3 2]), [], size(a, 2))
without a loop.

その他の回答 (1 件)

Matt J
Matt J 2018 年 10 月 12 日
Another way,
Acell=num2cell(A,[1,2]);
B=vertcat(Acell{:});

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by