フィルターのクリア

How Change Matrix Shape / Setting

3 ビュー (過去 30 日間)
Juan Pablo
Juan Pablo 2019 年 12 月 3 日
コメント済み: Juan Pablo 2019 年 12 月 4 日
I should arrange the matrix [Nx, 2, Nz] in a matrix [(Nx*Nz)/4, 8], where Nx and Nz are always even numbers,
I was trying to get this new array with this matrix [16 x 2 x 6] and get the final matrix [24 x 8],
M1.1 (2).png
and using the following code, where X = [16 x 2 x 6]
First I create a only array with concatenate function:
A = [];
for n = 1:size(X,3)
A = cat(1,A,X(:,:,n));
end
And get the matrix A = [96 x 2], and for getting the final matrix, I was using this code line:
B=cell2mat(mat2cell(reshape(A',4,[]),4,repmat(numel(A)/8,1,2))')';
As it is explained in the graph, I want to join the first 2 columns and 2 rows of Nz(1) (4 elements) and Nz(2) (4 elements) in only one row with 8 columns.
The line code works with some arrays but not with all of them.
If someone of you can help with this, I would appreciate your contribution.

採用された回答

David Hill
David Hill 2019 年 12 月 3 日
This might not be the best way, but it works.
C=[];
c=1;
for k=2:2:size(val,3)
B(:,:,c)=[val(:,:,k-1),val(:,:,k)];%horizontal cat
c=c+1;
end
for k=1:size(val,3)/2
C=[C;B(:,:,k)];%vertical cat
end
C=C';
C=reshape(C,8,[])';%reshape to your desire
  1 件のコメント
Juan Pablo
Juan Pablo 2019 年 12 月 4 日
Thank for your help David!. It was very helpful!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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