2D plot with linked Nan values
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

