Put the leading number corresponding to the number in the column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
Is there a technique to put numbers based on the row position?.For example: I'm interested in putting numbers starting with number one in column 1, numbers starting with two in column 2, and so on (see red arrow below). for details can be seen in the following illustration:
for the data are:
rowcell={'10302','20245','30108','40112','52013','85911',[],[];'10268',[],'30095','40099','52014','69944','81502',[];'10308','20258','30054','40058','57019','83511',[],[];'10307','20258','30073','40077','57018','60021','70162','83511';'10325','20232','30082','40086',[],[],[],[];'10276','20228',[],'40085','52013','81531',[],[]}
or see attachment..
much appreciated help, tks great community.
0 Kommentare
Akzeptierte Antwort
Voss
am 4 Jun. 2022
rowcell={'10302','20245','30108','40112','52013','85911',[],[];'10268',[],'30095','40099','52014','69944','81502',[];'10308','20258','30054','40058','57019','83511',[],[];'10307','20258','30073','40077','57018','60021','70162','83511';'10325','20232','30082','40086',[],[],[],[];'10276','20228',[],'40085','52013','81531',[],[]}
% replace empty cells with '0':
empty_idx = cellfun(@isempty,rowcell);
rowcell(empty_idx) = {'0'};
% get the first digit, to be used as column index:
idx = cellfun(@(x)x(1)-'0',rowcell);
% build result:
n_row = size(rowcell,1);
rowcell_arrange = cell(n_row,max(idx(:)));
for ii = 1:n_row
% each row of the result has the non-empty cells from that row of rowcell,
% put in column locations given by idx(ii,:) where idx(ii,:) > 0
rowcell_arrange(ii,idx(ii,idx(ii,:) > 0)) = rowcell(ii,~empty_idx(ii,:));
end
disp(rowcell_arrange)
4 Kommentare
Voss
am 6 Jun. 2022
Well, that's quite a different situation than the original question. I recommend starting a new question and maybe someone can figure it out.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots 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!