Adding elements of double arrays inside cell array below another double array inside the same cell array
2 次查看(过去 30 天)
显示 更早的评论
Hello!!!!! I have a problem on dealing with cell array. I would like to ask for some help. So, my problem is that I have on cell array. Inside this cell array, there are a lot of double arrays in each cell element. The thing is that I would like to put double arrays (inside this cell) below another double array. Here are my example in file attached. "Example.mat" contains the cell array named as "Sort". and "Solution.mat" contains solutions of double array I would like to have. Sometimes, I would like to have solution as A1 array which is the solution of adding three arrays together. Another time I may want to have solution of adding two array together as shown in A4.
Here are how A1, A2, A3 are derived.
A1=[Sort{1,1}; Sort{1,2}; Sort{1,3}];
A2=[Sort{2,1}; Sort{2,2}; Sort{2,3}];
A3=[Sort{3,1}; Sort{3,2}; Sort{3,3}];
A4=[Sort{3,1}; Sort{3,2}];
Note that this example is just a small part of my real cell arrays. The actual cell array is very huge and the difficult part is that I want to make it dynamically without doing in term of [Sort{1,1}; Sort{1,2}; .....; Sort{1,n}]; where n is the last column in cell array I would like to add double array in n cell to other array.
Thank you in advance.
1 个评论
Stephen23
2019-4-23
"Adding elements ..."
You are not "adding" those arrays, you are concatenating them:
采纳的回答
Stephen23
2019-4-23
编辑:Stephen23
2019-4-23
Concatenating the contents of a cell array is easy using a comma-separated list:
>> A1 = cat(1,Sort{1,:})
A1 =
1 2
3 4
5 6
4 5
6 7
>> A2 = cat(1,Sort{2,:})
A2 =
10 20
30 40
50 60
40 50
60 70
>> A3 = cat(1,Sort{3,:})
A3 =
100 200
300 400
500 600
400 500
600 700
Read about comma-separated lists:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!