1

I tried to read to .txt files in Matlab that include monthly information about solar radiation and temperatures. The months are as text i.e Jan, Feb, etc. Then with this information need to make some graphs to display the information per month, like for example monthly solar radiation having the months in the x-axis. Beyond that need to plot two graph on the same figure since I have Matlab 2015b need to use plotyy. THE PROBLEM: I thought that the months were correct read from the file, but when I plot takes all the months as January so I cannot plot correctly two graphs since the times are different.

The code that using is:

  fidata = fopen('Asmara-mon2.txt', 'r' );
   formatSpeci = '%s';
    N1 = 9;
%     h1=('Month' 'Temp'  'Tamin' 'Tadmin' 'Tadmax' 'Tamax' 'RH');
   h3 = textscan(fidata,formatSpeci,N1,'Delimiter','|');
    asmara_precipitation= textscan(fidata,'%{MM}D %f %f %f %f %f %f %f %f');
%     formatIn = 'mm';
asmara_precipitation{1}=datenum(asmara_precipitation{1});
asmara_precipitation=cell2mat(asmara_precipitation); %% Month|  H_Gh|   SDm |SDd|SDastr |RR |RD |FF |DD
[MonthNum, MonthString] = month(asmara_precipitation(:,1));

p=find(average_day_radiation(:,1)<10);
q=find(diff(p)==1);
idx=[p average_day_radiation(p) average_day_radiation(p,2) average_day_radiation(p,4)];
consecutive_idx=[p(q) idx(q,2) idx(q,3) idx(q,4)];

% Graphic of bad radiation days

figure (44)

hold on

 plotyy(MonthNum,asmara_precipitation(:,7),consecutive_idx(:,1),consecutive_idx(:,2)) 
datetick('x','mmm')

Thank you in advance for any help and sorry to ask something that could seem silly.

  • I assume the first column, 'Month' is not in a supported date format. You should take a look on the online documentation of the month() function at https://www.mathworks.com/help/finance/month.html#inputarg_F – Captain Future May 09 '17 at 10:22
  • Hey thanks I solved the issue already :) Should I post here or just delete my question? – Andrea Fajardo May 12 '17 at 09:38

1 Answers1

0

Just keep the last line, and add the following line above the plot command:

% The acquisition exact date: 2017-<MonthNum>-01 12:00:00
MonthNum=datenum(2017,MonthNum,1,12,0,0); 

That will convert the MonthNum into a proper date, in which datetick will understand.

Brethlosze
  • 1,533
  • 1
  • 22
  • 41