Concatenate vector in a 3d matrix

3 次查看(过去 30 天)
Hi. I have these vectors: a = [11 12 13 14]; b = [21 22 23 24]; c = [31 32 33 34]; d = [41 42 43 44];
I want to concatenate them in a 2x2x4 matrix: M(:,:,1) = [11 21; 31 41]; M(:,:,2)= [12 22; 32 42]; and so on.
How can I do that?

采纳的回答

James Tursa
James Tursa 2012-4-13
For your exact problem:
M = reshape([a;c;b;d],2,2,4);
Then generalize as appropriate. E.g., if a,b,c,d are not row vectors to start with,
M = reshape([a(:)';c(:)';b(:)';d(:)'],2,2,4);
etc.
  4 个评论
Alessandro Masullo
Alessandro Masullo 2012-4-13
I would like to avoid cycles... :)
James Tursa
James Tursa 2012-4-13
MtimesV = mtimesx(M,V,'speed');
You can find mtimesx on the FEX here:
http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by