Put the leading number corresponding to the number in the column
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2022-6-4
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 个评论
Voss
2022-6-6
Well, that's quite a different situation than the original question. I recommend starting a new question and maybe someone can figure it out.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!