Azzera filtri
Azzera filtri

how to change NaN values using ratio

2 visualizzazioni (ultimi 30 giorni)
KangMin Koo
KangMin Koo il 3 Set 2018
Modificato: KangMin Koo il 3 Set 2018
Hello dear all,
I have a problem to solve my data on matlab.
There are many time series units such as [778.2, 778.2, 778.3, NaN, NaN, NaN, 778.6, 778.7, 778.8, NaN, 778.8,...]
It's exactly a cumulative data getting an increased.
So, I can calculate each differences are back - forth for each values [0.0000, 0.1000, NaN, NaN, NaN, NaN, 0.1000, 0.1000, NaN, NaN, ...]
but I wanna change that 'NaN' values using another ratio.
for example, ratio = [0.0167, 0.0224, 0.0129 ,0.0102 ,0.0109 ,0.0116 ,0.0201, 0.0578, 0.0750, 0.0528,...]
we can obtain differences from known values as 778.6 - 778.3 = 0.3 , 778.8 - 778.8 = 0
first NaN is 0.3*(0.0102/(0.0129+0.0102+0.0109+0.0116))+ 778.3 = 778.3668511
second NaN is 0.3*(0.0116/(0.0129+0.0102+0.0109+0.0116))+ 778.3 = 778.3763248
third NaN is 0.3*(0.0109/(0.0129+0.0102+0.0109+0.0116))+ 778.3
forth NaN is 0*(0.0528/(0.0750+0.0528))+778.8 = 778.8
I tried many things using diff(), but I cannot find a simple way to get that result.
If anyone can help, it would be greatly appreciated.
Thank you!

Risposte (2)

John D'Errico
John D'Errico il 3 Set 2018
Modificato: John D'Errico il 3 Set 2018
Be clear about your goal.
vec = 1:12;
vec([3 4 5 7 8 11]) = NaN
vec =
1 2 NaN NaN NaN 6 NaN NaN 9 10 NaN 12
Do you want to find ANY NaN?
find(isnan(vec))
ans =
3 4 5 7 8 11
Do you want to find all pairs of consecutive NaNs? This will work, finding the first of each pair of consecutive NaNs.
nanlocs = strfind(isnan(vec),[1 1])
nanlocs =
3 4 7
All strings of NaNs, of any length? So, this will find the beginning of any sequence of NaNs, even as short as length 1.
nanlocs = strfind([0,isnan(vec)],[0 1])
nanlocs =
3 7 11
If you want to exclude the singleton NaNs, then you could do this:
nanlocs = setdiff(strfind([0,isnan(vec)],[0 1]),strfind([0,isnan(vec)],[0 1 0]))
nanlocs =
3 7
Lots of other ways, I'm sure. And it will be easy enough to find the length of those sequences, or the endpoints. (Hint: consider what I did above. How might you modify it to find the endpoint of such a sequence of NaNs? What would that tell you about the length?)
  1 Commento
KangMin Koo
KangMin Koo il 3 Set 2018
thank u so much John, what I'm saying is how to change that NaN values using ratio. actually it's meter data. I just want to change a missing data using ratio...

Accedi per commentare.


Tiasa Ghosh
Tiasa Ghosh il 3 Set 2018
if
A=[778.2; 778.2; 778.3; NaN; NaN; NaN; 778.6; 778.7; 778.8; NaN; 778.8]
then maybe you could search for all the rows containing NaN by
find(any(A==NaN,2))

Community Treasure Hunt

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

Start Hunting!

Translated by