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.

 Accepted Answer

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 Comments

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.
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

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

on 13 Jan 2014

Commented:

on 13 Jan 2014

Community Treasure Hunt

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

Start Hunting!