Only dataset that won't plot correctly

2 views (last 30 days)
On all my other plots I have done with this code they have worked out fine, but for some reason this has not. Any advice?
This is my script for my plot:
function plot_CHL_data(data)
% function to plot the Giovanni data imported with load_giovanni_data
figure(1)
clf
plot(data.t,data.CHL,'.b-')
datetick('x')
ylabel('Chlorophyll Time Series', 'fontsize', 16)
xlabel('Date', 'fontsize', 16)
and this is my script to load the data:
function data=load_CHL_data(filename)
% function to load tide data from Giovanni
% input is the filename of the data file
% output is the date/time and SST from the data file
% tmp=tempory l=line
data.filename=filename;
fid=fopen(filename);
%Skips headerlines
for I=1:10
tmpl=fgetl(fid);
end
J=1;
while ischar(tmpl)
%5 strings
tmp=textscan(tmpl,'%s %f','Delimiter',',');
data.t(J)=datenum( cell2mat(tmp{1}) );
data.CHL(J)=tmp{2};
tmpl=fgetl(fid);
J=J+1;
end
%(-32767) == NaN;
fclose(fid);
I've also attached the file, as I think there might be something wrong with the data.
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 26 Dec 2019
Replace
%(-32767) == NaN;
with
data.CHL(data.CHL==-32767) = NaN;
  5 Comments
Walter Roberson
Walter Roberson on 29 Dec 2019
Yup, that's all.
function data=load_CHL_data(filename)
% function to load tide data from Giovanni
% input is the filename of the data file
% output is the date/time and SST from the data file
% tmp=tempory l=line
data.filename=filename;
fid=fopen(filename);
%Skips headerlines
for I=1:10
tmpl=fgetl(fid);
end
J=1;
while ischar(tmpl)
%5 strings
tmp=textscan(tmpl,'%s %f','Delimiter',',');
data.t(J)=datenum( cell2mat(tmp{1}) );
data.CHL(J)=tmp{2};
tmpl=fgetl(fid);
J=J+1;
end
data.CHL(data.CHL==-32767) = NaN;
fclose(fid);
together with
function plot_CHL_data(data)
% function to plot the Giovanni data imported with load_giovanni_data
figure(1)
clf
plot(data.t,data.CHL,'.b-')
datetick('x')
ylabel('Chlorophyll Time Series', 'fontsize', 16)
xlabel('Date', 'fontsize', 16)
Miriam Daughtery
Miriam Daughtery on 3 Jan 2020
Thanks, I plotted it on another computer and it worked.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!