Filter löschen
Filter löschen

order a column of matrix respect to another column

5 Ansichten (letzte 30 Tage)
franco otaola
franco otaola am 19 Aug. 2020
Bearbeitet: Bruno Luong am 19 Aug. 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 Kommentare
KSSV
KSSV am 19 Aug. 2020
How did you insert NaN's in between? What is the criteria?
franco otaola
franco otaola am 19 Aug. 2020
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)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 19 Aug. 2020
Bearbeitet: Bruno Luong am 19 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by