Put the leading number corresponding to the number in the column

1 次查看(过去 30 天)
Hi all,
Continue the previous discussion here but now on a different topic.
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.

采纳的回答

Voss
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',[],[]}
rowcell = 6×8 cell array
{'10302'} {'20245' } {'30108' } {'40112'} {'52013' } {'85911' } {0×0 double} {0×0 double} {'10268'} {0×0 double} {'30095' } {'40099'} {'52014' } {'69944' } {'81502' } {0×0 double} {'10308'} {'20258' } {'30054' } {'40058'} {'57019' } {'83511' } {0×0 double} {0×0 double} {'10307'} {'20258' } {'30073' } {'40077'} {'57018' } {'60021' } {'70162' } {'83511' } {'10325'} {'20232' } {'30082' } {'40086'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {'10276'} {'20228' } {0×0 double} {'40085'} {'52013' } {'81531' } {0×0 double} {0×0 double}
% 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)
{'10302'} {'20245' } {'30108' } {'40112'} {'52013' } {0×0 double} {0×0 double} {'85911' } {'10268'} {0×0 double} {'30095' } {'40099'} {'52014' } {'69944' } {0×0 double} {'81502' } {'10308'} {'20258' } {'30054' } {'40058'} {'57019' } {0×0 double} {0×0 double} {'83511' } {'10307'} {'20258' } {'30073' } {'40077'} {'57018' } {'60021' } {'70162' } {'83511' } {'10325'} {'20232' } {'30082' } {'40086'} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {'10276'} {'20228' } {0×0 double} {'40085'} {'52013' } {0×0 double} {0×0 double} {'81531' }
  4 个评论
eko supriyadi
eko supriyadi 2022-6-6
编辑:eko supriyadi 2022-6-6
Hi Voss, i have another problem
How if the putting it's not based on the lead number?. But from inputting numbers that I have, say i have lead number like: 1, 2, 5, 55, 555, 56, 57, 58, 59, 8. In other word, i want all numbers that lead by 1 places in column 1, lead 2 in column 2, lead 5 in column 3, lead 55 in column 4, .... lead 8 ini column 10..
edited: forgot the data
rowcell={'10302','20245','50108','55112','58013','85911',[],[];
'10268',[],'55095','56099','58014','59944','81502',[];
'10308','20258','50054','55558','56019','83511',[],[];
'10307','20258','50073','55077','56018','56021','58162','83511';
'10325','20232','50082','55086',[],[],[],[];
'10276','20228',[],'56085','59013','81531',[],[]};
this ilustration:
Voss
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 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by