필터 지우기
필터 지우기

order a column of matrix respect to another column

조회 수: 5 (최근 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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by