order a column of matrix respect to another column
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Bruno Luong
2020-8-19
编辑:Bruno Luong
2020-8-19
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!