How to concatenate horizontally a cell into another cell based on a vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
endystrike
am 13 Apr. 2021
Kommentiert: endystrike
am 13 Apr. 2021
Hi,
I want to concatenate horizzontally with a criteria based on a vector this cell into another cell. All the double matrices inside the "wl_tmp" cell have the same number of rows, but not the same number of colums!
I have this vector and in my idea, the elements with the same value should be grouped together (concatenating them horizontally from left to right).
For example: the final cell is "wl_final":
wl_final{1} = [wl_tmp{1}, wl_tmp{2}, wl_tmp{3}, wl_tmp{4}, wl_tmp{5}, wl_tmp{6}, wl_tmp{7}, wl_tmp{8}, wl_tmp{9}, wl_tmp{10}, wl_tmp{11}];
wl_final{2} = [wl_tmp{12}, wl_tmp{13}];
%and so on...
I found a solution with a for loop but because of the high amount of data, it's terribly slow and I wanted to figure out how I could use "accumarray" instead, but I cannot understand how that function works exactly and how to use it for my purposes.
wl_tot = length(wl_idx);
wl_final = cell(1,length(pX_i_ref_wl)); %"pX_i_ref_wl" contains just the name of the groups: in this case is a 1x11 string
clear tmp;
for k=1:wl_tot
if wl_idx(k)~=wl_idx(max(k-1,1)) || k==1
tmp = wl_tmp{k};
else
tmp = [tmp, wl_tmp{k}]; %#ok<AGROW>
end
if k==wl_tot || wl_idx(k+1)~=wl_idx(k)
wl_final{wl_idx(k)} = tmp;
clear tmp;
end
end
P.S. I cannot group them before, because the "wl_tmp" comes from a parfor loop with sliced variables and I'd prefer to group them later!
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!