Reshaping cell array having element with different sizes
2 次查看(过去 30 天)
显示 更早的评论
I have a variable named A which is a 5000×4 cell array containing M×2 matrices. M varies for each element. 5000 is the number of different measurement for 4 profiles. The following shows only two out of 5000 measurements. First row shows measurement#1 and the second row is measurement#2:
[3413x2 double] [3082x2 double] [3186x2 double] [3143x2 double]
[3344x2 double] [3044x2 double] [3200x2 double] [3143x2 double]
I am trying to have all the profile for each measurement in one matrix of size N×2, named B. for example, for the first measurement N=3413+3082+318+3143=12824. So, B is vertcat of the first row of A, it means B is constructed by putting each profile under the previous profile. finally B{i} will be all the profiles for ith measurement.
Could you help me with that?
0 个评论
采纳的回答
Andrei Bobrov
2011-6-15
A1 = A';
B = arrayfun(@(x)cat(1,A1{:,x}),1:size(A1,2),'un',0)
3 个评论
Andrei Bobrov
2011-6-16
Hi! Having seen Your solution to <http://www.mathworks.com/matlabcentral/answers/9600-subtracting-a-constant-from-all-the-array-elements-in-a-structure>, think that the explanation is not needed?
更多回答(1 个)
Walter Roberson
2011-6-15
I think this might work:
B = arrayfun(@(idx) [A{idx,:}], 1:size(A,1), 'un', 0);
3 个评论
Walter Roberson
2011-6-15
Ah, try
B = arrayfun(@(idx) vertcat(A{idx,:}), 1:size(A,1), 'un', 0);
You use arrayfun instead of cellfun because cellfun processes each cell individually whereas you want to process groups of cells.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!