Grouping matrices under a

Hi,
So it is straight forward to do the following,
A = [2; 6; 7; 8; 6]
B = [7; 1; 6; 3; 4; 9; 8]
C= [A;B] = [2; 6; 7; 8; 6; 7; 1; 6; 3; 4; 9; 8]
Assume that I have several of these matrices that I need to "group". How can I write some code which will do the above but be flexible enough to recognise how many matrices I need to group (the number will vary).
Hope that makes sense.
Craig

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 11 de Sept. de 2013
Editada: Azzi Abdelmalek el 11 de Sept. de 2013

0 votos

vertcat(A,B)
If you have many arrays. For example
a=[]
for k=1:10
x=(1:k)'
a=vertcat(a,x)
end
%or
vertcat(a,b,c,d)

2 comentarios

Craig
Craig el 11 de Sept. de 2013
perfect thanks!
Jan
Jan el 11 de Sept. de 2013
While loop suffers from a missing pre-allocation, using VERTCAT is clean and clear.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 11 de Sept. de 2013

0 votos

If you use a function to do the stitching, then look at nargin - it will tell you how many input arguments you have, and then varargin will be a cell array with however many arguments you passed in. Then you can loop over that, extracting and stitching as needed.

1 comentario

Image Analyst
Image Analyst el 11 de Sept. de 2013
For example
stitched1 = myStitch(a,b); % Stitch 2 matrices.
stitched2 = myStitch(a,b,c,d,e,f,g,h); % Stitch 8 matrices.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Sept. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by