Only dataset that won't plot correctly

조회 수: 2 (최근 30일)
Miriam Daughtery
Miriam Daughtery 2019년 12월 26일
댓글: Miriam Daughtery 2020년 1월 3일
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

채택된 답변

Walter Roberson
Walter Roberson 2019년 12월 26일
Replace
%(-32767) == NaN;
with
data.CHL(data.CHL==-32767) = NaN;
  댓글 수: 5
Walter Roberson
Walter Roberson 2019년 12월 29일
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 2020년 1월 3일
Thanks, I plotted it on another computer and it worked.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by