2D plot with linked Nan values
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Giuditta CELLI
am 21 Jul. 2022
Kommentiert: Abderrahim. B
am 21 Jul. 2022
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?
0 Kommentare
Akzeptierte Antwort
Abderrahim. B
am 21 Jul. 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polar Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

