help-octave
[Top][All Lists]

## Re: Filling the gaps in data arrays

 From: Doug Stewart Subject: Re: Filling the gaps in data arrays Date: Wed, 11 Jul 2018 14:54:32 -0400

On Wed, Jul 11, 2018 at 10:37 AM, Mat086 wrote:
Hello everybody,
I'm dealing with a little problem here and I'm a newbie with Octave,
although I used Matlab previously.

I have an [x y] dataset containing x positions and peaks. However, only data
for the peaks are presents and between them nothing. Let me explain better
with a simple example:

x = [1 2 3 4 5 6 7 8 9    27 28 29 30 31 32 33 34 35     56 57 58 59 60 61
62 63 64 ]
y = [0.1 0.5 1 5 25 5 1 0.5 .1     0.3 0.5 1.5 15 44 15 1.5 0.5 .3     0.3
0.2 3 9 23 9 3 0.2 .3 ]

As you can see, the step in x array is fixed to x(2)-x(1)=1 (in this
example), but there are gaps in both x and y in regions where background is
supposed to be flat.
However, In order to analyze such kind of data with another software I need
to create X and Y vectors without holes. Therefore, I should create an X
array X=[1:step:64], of length=64, and Y array of the same length, having
the peaks at the same positions of [x y] and zeros where there were gaps in
x. There was an in built function in Matlab ("fillmissing" if I remember
well), but I'm struggling to get this done in Octave.
Any help would be greatly appreciated!

thanks,
Matt

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

Here is one wah to do it;

x = [1 2 3 4 5 6 7 8 9 27 28 29 30 31 32 33 34 35 56 57 58 59 60 61 62 63 64 ]
y = [0.1 0.5 1 5 25 5 1 0.5 .1 0.3 0.5 1.5 15 44 15 1.5 0.5 .3 0.3 0.2 3 9 23 9 3 0.2 .3 ]

xx(64)=0
for k=1:27
xx(x(k))=y((k));
endfor
plot(xx)
xx

--
DAS