help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filling the gaps in data arrays


From: Mat086
Subject: Re: Filling the gaps in data arrays
Date: Thu, 26 Jul 2018 09:47:23 -0500 (CDT)

Przemek Klosowski-7 wrote
> On 07/12/2018 04:36 AM, Mat086 wrote:
>> dx = x(2)-x(1);
>> Y = zeros(1,length([min(x):dx:max(x)]));
>> X = [min(x):dx:max(x)];
>> for k=1:length(x)
>>    indx = find(X==x(k));
>>    Y(k) = y(index);
>> endfor
>> plot(x,y,'b-'); hold on; plot(X,Y,'-o');
> 
> you meanĀ  Y(k) = y(indx); , right?
> 
> And no, it won't work in Matlab either because you are doing exact 
> floating point comparisons on calculated values, so any roundoff will 
> trip you up---check for yourself, X==X(3) returns matches, but X==x(3) 
> probably doesn't.
> 
> You said that "In order to analyze such kind of data with another 
> software I need to create X and Y vectors without holes". What is 
> exactly the assumption there? Is the original dataset sampled on a 
> regular grid, and the non-zero values are dropped?
> 
> It seems to me that the best solution for you would be to interpolate 
> your data onto a regular grid, perhaps like this:
> 
> dx=x(2)-x(1);
> 
> plot(x,y,'x',X=min(x):dx:max(x),interp1(x,y,X))


Hi Przemek,
thanks for your reply!
I don't need to interpolate the data, actually the best thing would be to
have NaN where the y-data doesn't match the X vector.
this script is doing what I needed to do:

dx = x(2)-x(1);
Y = zeros(1,length([min(x):dx:max(x)]));
X = [min(x):dx:max(x)];
st=1;
for k=1:length(X)
  if isempty(y(x==X(k))) 
    Y(k) = 0;
  else 
    Y(k) = y(st);
    st=st+1;
  end
end

thanks again,
Mat



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]