2D plot with linked Nan values

조회 수: 24 (최근 30일)
Giuditta CELLI
Giuditta CELLI 2022년 7월 21일
댓글: Abderrahim. B 2022년 7월 21일
I have one vector with 32 latitude points, and another vector with sodium values for each point, but the point number 10 is a Nan value. So, I have to plot them as x=latitude and y=sodium, and I do not want the gap betwen point 9 and 11, but a connection.
I already tried this code
plot(latitude,sodium)
ln=plot(latitude,sodium);
ln.Color=[0 0 0];
ln.LineWidth=1.5;
ln.Marker="o";
ln.MarkerFaceColor=[0 0 0];
x = [latitude 9, latitude 11];
y = [sodium 9, sodium 11];
plot(latitude,sodium,"k",x,y,"k")
it worked but at one point it did not work anymore (I have a 2D line but without marker).
So I changed the last three lines and tried with this code
y1=sodium(~isnan(sodium);
x1=latitude(~isnan(sodium));
Also in this case in worked at the beginning, but now it doesn't work anymore.
How is ti possible that they stopped to work and how can I connect the gap?

채택된 답변

Abderrahim. B
Abderrahim. B 2022년 7월 21일
Hi!
Perhaps the below code works for you:
clear
close all
% Creating dummy data
latitude = 1:32 ;
sodium = rand(1,32) ;
sodium (10) = NaN ;
% Plot initial data
figure ("Name", "Plot with Gap")
plot(latitude, sodium, 'r')
% Check if ur data has some NaNs and see how many, then fill NaN
ismissing_sod = numel(nnz(sodium)) ;
sodiumClean = fillmissing(sodium,"linear") ;
% Plot cleaned data
figure ("Name", "Plot with No Gap")
plot(latitude, sodiumClean, 'k')
Hope this helps
  댓글 수: 2
Giuditta CELLI
Giuditta CELLI 2022년 7월 21일
Thank you! It seems to work for now, and I'm able to have again the markers for each values.
Abderrahim. B
Abderrahim. B 2022년 7월 21일
Welcome! Always a pleasure to help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by