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.

 Accepted Answer

KSSV
KSSV on 19 May 2021
Edited: KSSV on 19 May 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 Comments

Thanks for your help, but it doesn't seem to work properly.
You need to provide the indices. Edited the code.
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:
Edited the code.....you can also use fillmissing an inbuilt function to fill the missing/ NaN values.
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')

Sign in to comment.

More Answers (0)

Categories

Asked:

on 19 May 2021

Commented:

on 19 May 2021

Community Treasure Hunt

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

Start Hunting!