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.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 13 Jan. 2014
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 Kommentare

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 am 13 Jan. 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 13 Jan. 2014

Kommentiert:

am 13 Jan. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by