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.

 采纳的回答

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 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by