order a column of matrix respect to another column

1 回表示 (過去 30 日間)
franco otaola
franco otaola 2020 年 8 月 19 日
編集済み: Bruno Luong 2020 年 8 月 19 日
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 件のコメント
KSSV
KSSV 2020 年 8 月 19 日
How did you insert NaN's in between? What is the criteria?
franco otaola
franco otaola 2020 年 8 月 19 日
it is exaclty where i can not find how to do it. where i am now:
load('c.mat')
varPeaks=30;
Max=max(NpeaksSignal);
for i=1:numFiles
if NpeaksSignal(i)<Max
c{i}=[c{i};NaN(Max-length(c{i}),1)];
for j=1:Max
[~,newPos]=find(c{Max}(:,:)>=c{i}(j)-varPeaks&c{Max}(:,:)<=c{i}(j)+varPeaks);
dummy=c{i}(newPos);
c{i}(newPos)=c{i}(j);
c{i}(newPos)=dummy;
end
end
end
in c.mat the one that needs to arranged is column 1. but I do not understand why the last loop does nothing... (is what it is supposed to order c)

サインインしてコメントする。

採用された回答

Bruno Luong
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by