How to fill empty spaces and mark them on plot?

Hi there! I'm having an issuse with filling empty elements and then marking them with red dots. Here is what i got:
F = standardizeMissing(d1, Inf);
F(isnan(F))=0;
plot(F,'.r', 'MarkerSize', 15)
hold on
plot(F,'b')
It fills the empty values but on the plot, it marks all of the points, not only the ones that were empty.

 Respuesta aceptada

KSSV
KSSV el 19 de Mayo de 2021
Editada: KSSV el 19 de Mayo de 2021
idx = isnan(F);
id1 = find(idx) ;
id2 = find(~idx) ;
% Fill missing
F(idx) = interp1(id2,F(id2),id1) ;
plot(id1,F(idx),'.r', 'MarkerSize', 15)
hold on
plot(1:length(F),F,'b')

7 comentarios

Alicja Kozik
Alicja Kozik el 19 de Mayo de 2021
Thanks for your help, but it doesn't seem to work properly.
KSSV
KSSV el 19 de Mayo de 2021
You need to provide the indices. Edited the code.
Alicja Kozik
Alicja Kozik el 19 de Mayo de 2021
I think you didn't actually understand what I mean. I have to fill missing places and put red dots where the misssing places existed. Like in this example:
KSSV
KSSV el 19 de Mayo de 2021
Edited the code.....you can also use fillmissing an inbuilt function to fill the missing/ NaN values.
Alicja Kozik
Alicja Kozik el 19 de Mayo de 2021
I've tried with fillmissing as well. Didn't work for me. I applied the code you sent me, the NaN values are changing, but the values that were previously NaN are still not marked with the red dots.
F = rand(1,10) ;
F(2) = NaN ;
F(5) = NaN ;
F(7) = NaN ;
idx = isnan(F);
id1 = find(idx) ;
id2 = find(~idx) ;
% Fill missing
F(idx) = interp1(id2,F(id2),id1) ;
plot(id1,F(idx),'.r', 'MarkerSize', 15)
hold on
plot(1:length(F),F,'b')
Alicja Kozik
Alicja Kozik el 19 de Mayo de 2021
Thanks a lot!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Preprocessing en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Mayo de 2021

Comentada:

el 19 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by