Concatenating a range of variables into a 3D array

I need to concatenate a range of variables into a 3D array. I have loaded my csv files into my workspace and can concatenate the data using "MyArray = cat(3, x1, x2, x3);" where x1,x2,x3 are the names of the variables
This gives the array structure I require however I have 100 csv files i.e. x1,x2,.....,x100 and I would like specify the range of variables rather than actually entering all 100 variables.

 Respuesta aceptada

example
x1=10;
x2=20;
x3=30;
x4=40;
eval(['cat(3' sprintf(',x%d',1:4) ')'])
But the problem is, how did you come up to all those variables, when it's possible to use just one variable containing all your data.

3 comentarios

Robert commented
Thanks for the answer. I didn't explain properly that each of these variables is actually a 186 rows by 61 columns. x1, x2, etc is just the name of the variable.
This is not important
Robert
Robert el 13 de En. de 2014
Thank you Azzi, that works perfectly. The actual code I used is below:
MyArray = eval(['cat(3' sprintf(',x%d',1:100) ')'])
size (MyArray) returns 186 61 100 which is absolutely correct

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Preguntada:

el 13 de En. de 2014

Comentada:

el 13 de En. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by