How to prevent array form combining
5 次查看(过去 30 天)
显示 更早的评论
I have an array in which each value is the variable of another array. My issue is that the arrays inside of the main keep combining into a single array and I need them to remain seperate. This is the problem:
Sub arrays: A1 = [1 2 3] A2 = [4 5 6] A3 = [7 8 9]
Main Array: A = [A1 A2 A3] = [1 2 3 4 5 6 7 8 9]
The issue is, I need to be able to use A1, A2, and A3 as individual array. When I use A(1) to denote the first array A1 = [1 2 3], the main array only gives the number 1 as it has combine all the array and gives the first value in the combination. I know this can be done by using A(1:3), but this will not work since the program contains hundreds of data sets. If anyone can tell me how to maintain the integrity of my array, with an example preferably, it would be much appreciated
0 个评论
采纳的回答
Walter Roberson
2021-1-23
A1 = [1 2 3]; A2 = [4 5 6]; A3 = [7 8 9];
A = {A1, A2, A3}
A{1}
Notice the use of {} for indexing to get to the content of the first "cell".
Note that you will not be able to do mathematics directly on A. For example, you will not be able to do something like
A = A + 1;
Instead you would need something like
A = cellfun(@(C) C+1, A, 'uniform', 0);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!