Put the leading number corresponding to the number in the column

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Voss
Voss el 4 de Jun. de 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',[],[]}
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 comentarios
eko supriyadi
eko supriyadi el 6 de Jun. de 2022
Editada: eko supriyadi el 6 de Jun. de 2022
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 el 6 de Jun. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by