문제

I have a time stamp as follow.

Time =

  243.0000
  243.0069
  243.0139
  243.0208
  243.0278
  243.0347
  243.0417
  243.0486
  243.0556
  243.0625
  243.0694
  243.0764
  243.0833
  243.0903
  243.0972
  243.1042
  243.1111
  243.1181
  243.1250
  243.1319
  243.1389
  243.1458
  243.1528
  243.1597
  243.1667
  243.1736
  243.1806
  243.1875
  243.1944    

Now I have another two column vector.

ab =

 243.0300    0.5814
 243.0717    0.6405
 243.1134    0.6000
 243.1550    0.5848
 243.1967    0.5869

First column is 'Time2' and second column is 'Conc'.

 Time2 = ab(:,1);
 Conc  = ab(:,2);

Now I want to match 'Conc' based on 'Time2' with 'Time' but only filling with 'NaN'. Also 'Time2' is not exactly as 'Time'. I can use something like following

Conc_interpolated = interp1(Time2,Conc,Time)

but it does an interpolation with artificial data. I only want to match vector length by filling with 'NaN' in 'Conc' not with interpolated data.Any recommendations? Thanks

도움이 되었습니까?

해결책 2

My understanding is a little different, it doesn't add to Time but rather assigns each Conc to the nearst Time based on it's Time2:

 ind = zeros(size(ab,1),1); %//preallocate memory
 for ii = 1:size(ab,1)
    [~, ind(ii)] = min(abs(ab(ii,1)-Time)); %//Based on this FEX entry: http://www.mathworks.com/matlabcentral/fileexchange/30029-findnearest-algorithm/content/findNearest.m
 end

 Time(:,2) = NaN; %// Prefill with NaN
 Time(ind, 2) = ab(:,2)

This results in:

Time =

   243.00000         NaN
   243.00690         NaN
   243.01390         NaN
   243.02080         NaN
   243.02780     0.58140
   243.03470         NaN
   243.04170         NaN
   243.04860         NaN
   243.05560         NaN
   243.06250         NaN
   243.06940     0.64050
   243.07640         NaN
   243.08330         NaN
   243.09030         NaN
   243.09720         NaN
   243.10420         NaN
   243.11110     0.60000
   243.11810         NaN
   243.12500         NaN
   243.13190         NaN
   243.13890         NaN
   243.14580         NaN
   243.15280     0.58480
   243.15970         NaN
   243.16670         NaN
   243.17360         NaN
   243.18060         NaN
   243.18750         NaN
   243.19440     0.58690

for your example inputs

다른 팁

I try to guess what you want:

you have time vector A:

TimeA = ...
 [243.0000;
  243.0069;
  ...
  243.1875;
  243.1944];

and probably some data A:

DataA = rand(length(TimeA),1);

now you want to implement your second time vector B:

TimeB = ...
 [243.0300;    
  243.0717;    
  243.1134;    
  243.1550;    
  243.1967]; 

and the according data:

DataB = ...
 [0.5814;
  0.6405;
  0.6000;
  0.5848;
  0.5869];

finally everything should be merged together and sorted:

X = [ TimeA, DataA , NaN(size(DataA)) ; 
      TimeB, NaN(size(DataB)) , DataB ]

Y = sortrows(X,1);

results to:

Y =

  243.0000    0.8852       NaN
  243.0069    0.9133       NaN
  243.0139    0.7962       NaN
  243.0208    0.0987       NaN
  243.0278    0.2619       NaN
  243.0300       NaN    0.5814
  243.0347    0.3354       NaN
  243.0417    0.6797       NaN
  243.0486    0.1366       NaN
  243.0556    0.7212       NaN
  243.0625    0.1068       NaN
  243.0694    0.6538       NaN
  243.0717       NaN    0.6405
  243.0764    0.4942       NaN
  243.0833    0.7791       NaN
  243.0903    0.7150       NaN
  243.0972    0.9037       NaN
  243.1042    0.8909       NaN
  243.1111    0.3342       NaN
  243.1134       NaN    0.6000
  243.1181    0.6987       NaN
  243.1250    0.1978       NaN
  243.1319    0.0305       NaN
  243.1389    0.7441       NaN
  243.1458    0.5000       NaN
  243.1528    0.4799       NaN
  243.1550       NaN    0.5848
  243.1597    0.9047       NaN
  243.1667    0.6099       NaN
  243.1736    0.6177       NaN
  243.1806    0.8594       NaN
  243.1875    0.8055       NaN
  243.1944    0.5767       NaN
  243.1967       NaN    0.5869

is that right?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top