How to reshape data for plot?

17 次查看(过去 30 天)
hit8hot
hit8hot 2016-1-27
评论: dpb 2016-1-27
Hello everyone, I am working with one year data(attached herewith) of latitudes (1st column) and electron contents (2nd column). File contains date at the top, number of data point (eg. 51) for each day then two columns data. This sequence is repeated for all days of the year 2008. I want days of the year (DOY) in one column and maximum value of electron content of each day in other column from the data file for the plot. Your help will be appreciated.

采纳的回答

dpb
dpb 2016-1-27
编辑:dpb 2016-1-27
That there are a differing number of entries per day makes it a little more of a challenge; that they kindly gave you the count instead of having to find out that number is a boon...
fid=fopen('lat_econtent.txt','rt'); % open file
da=fscanf(fid,'%d',3); % get first date
nDay=365+isleapyr(d(1)); % how many days in this year
eMax=zeros(nDay,2); % allocate space for that many
frewind(fid) % reposition to get clean start to loop
for i=1:nDay
da=fscanf(fid,'%d',3); % get first date
n=fscanf(fid,'%d',1); % get number observations for day
dat=cell2mat(textscan(fid,'',n)); % scan that many
[~,ix]=max(dat(:,2)); % find max location
eMax(i,:)=dat(ix,:); % get lat and max for first
end
fid=fclose(fid);
The result of the above here produced via
>> emax
>> subplot(2,1,1)
>> plot(1:length(eMax),eMax(:,2))
>> subplot(2,1,2)
>> plot(1:length(eMax),eMax(:,1))
NB: I included the location as well as the max; figured it would be the obvious next step despite your not having asked for it... :)
ADDENDUM
You don't need any additional variable for DOY; it's the same as the sequential storage location, 1:nDay.
Oh, and isleapyr is a one-liner utility routine --
function is=isleapyr(yr)
% returns T for input year being a leapyear
is=eomday(yr,2)==29;
  2 个评论
hit8hot
hit8hot 2016-1-27
Thank you. Your reply is greatly appreciated.
dpb
dpb 2016-1-27
No problem; glad to help. I've no klew what "electron content" really is, but it's an interesting pattern over the year.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by