Info

此问题已关闭。 请重新打开它进行编辑或回答。

Plot muliple data files into one plot

1 次查看(过去 30 天)
Miriam Daughtery
Miriam Daughtery 2019-12-16
关闭: MATLAB Answer Bot 2021-8-20
Hi, I've spent about 3 days trying to figure out how to plot muliple data files into 1 plot. I know it is possible as I have done it before. Basically I have 10 csv files of monthly data I want to plot. Below is a screen shot of how I can plot one but I cannot figure out how to combine the data to be able to plot the whole year.
I have also a
Screen Shot 2019-12-16 at 15.51.49.png
Also here is my script on how I have worked with the data I have got:
Function script:
function data=processfile(filename)
function data=processfile(filename)
% function to load data from COPEPOD
% input is the filename of the data file
% output is the Year/Month and Adundance from the data file
% tmp=tempory l=line
data.filename=filename; %each time i look at output data with contain name of data file it loaded data from
fid=fopen(filename); %opens up data file
%Skips headerlines
for I=1:18 %loop to repeat until the desired line is reached e.g. 18 is when the text that i am interested in starts
tmpl=fgetl(fid); %fgetl=function get line %fid=file identifier %tmpl=asssigned name of variable to capture each line
end
disp(tmpl)
J=1;
while ischar(tmpl)
% 21 strings
tmp=textscan(tmpl,'%s',32,'Delimiter',','); %takes the input of the loop line with format spec= what we are going to break it into e.g. %s = strings
tmp{1}(2)
data.date(J)=datenum( str2num( cell2mat(tmp{1}(2))), str2num( cell2mat(tmp{1}(3))),str2num( cell2mat(tmp{1}(4))))+str2num( cell2mat(tmp{1}(5)))/24; %year, month, day, time /fraction of day adding onto date
%data.P=str2num(cell2mat(tmp{1}(22))); %plankton amount %datestr(data1994_april.d) to display date properly
tmpPlankton=str2num(cell2mat(tmp{1}(22)));
if isempty(tmpPlankton)
tmpPlankton=NaN
end
data.Plankton(J)=tmpPlankton;
tmpl=fgetl(fid);
J=J+1;
end
Plotting script:
function plotdata(data)
% function to plot the Giovanni SST data imported with load_giovanni_data
figure(1)
clf
plot(data.date,data.Plankton,'.b-','MarkerEdgeColor','r','MarkerSize',17,'LineWidth', 1.5)
datetick('x')
ylabel('Plankton', 'fontsize', 16)
xlabel('Date', 'fontsize', 16)
%title('-4.9438,50.647,-4.7351,50.9436, 2002-2012 SST', 'fontsize', 14)
I will literally marry anyone who is able to figure this out. Thanks everyone
  1 个评论
dpb
dpb 2019-12-16
The key element to add additonal data to an existing axis is to call hold on before subsequent calls to plot() after the first. Otherwise, it simply begins a fresh plot each time.
Your code looks to be quite inefficient in handling lots of cell arrays that probably aren't needed but without one or two of the data files to see just what really have not much else we can do just looking at screen shots.
Code w/o data isn't of much help--better than no code because I didn't see the key missing element anywhere, but a complete working demo of the problem would be bestest...

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by