order a column of matrix respect to another column
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
franco otaola
el 19 de Ag. de 2020
Editada: Bruno Luong
el 19 de Ag. de 2020
hello,
i am looking at different data sets, that are in different cells, for examle:
c{1}=[1.25,5.05,7.2]; %so an double(3,1)
c{2}=[1,2,3,4,5,6,7]; %so an double(7,1)
i am looking to extend c{1} to the same size as c{2} with NaN
c{1}=[c{1},NaN(length(c{2}-c{1}))];%so it would be [1.25,5.05,7.2,NaN,NaN,NaN,NaN]
and what i am having issues to imagin an more or less efficient way to do, is to order c{1} so the numbers and in the same position as in c{2}+/-delta
C{1}=[1.25,NaN,NaN,NaN,5.05,NaN,7.2]
c is bigger than 2 and would like to do this for all the c{i} that are smaller than the one that has more elements inside (this case c{2} but could be another one, this position i could find it directly from max size and do the re arangement only if the size of c{i} is smaller than size(c{max})) but for the example i put it with only two.
2 comentarios
Respuesta aceptada
Bruno Luong
el 19 de Ag. de 2020
Editada: Bruno Luong
el 19 de Ag. de 2020
c{1}=[1.25,5.05,7.2]; %so an double(3,1)
c{2}=[1,2,3,4,5,6,7]; %so an double(7,1)
i = interp1(c{2},1:length(c{2}),c{1},'nearest','extrap');
c{1} = accumarray(i(:),c{1}(:),[length(c{2}) 1],[],NaN)';
Result
>> c{1}
ans =
1.2500 NaN NaN NaN 5.0500 NaN 7.2000
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!