Plotting precip and time data
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Natasha Sekhon
el 11 de Abr. de 2017
Comentada: Natasha Sekhon
el 12 de Abr. de 2017
Hi There, This is going to come across as a very simple question but i want to plot time on the x-axis in 'yyyy/mm/dd' format and precipitation on the y axis. I'm reading files from an excel data sheet but when i plot it using attached code, the x-axis looks weird. I know it has to do with the formatting but i'm not sure what... Any help is much appreciated! Thanks, Natasha
prcp_hope = xlsread('NCEI_CDO.xlsx','Hope','G:G'); prcp_hope(prcp_hope == -9999) = NaN;
datem_hope = xlsread('NCEI_CDO.xlsx','Hope','F:F');
plot(datem_hope,prcp_hope)
0 comentarios
Respuesta aceptada
KSSV
el 11 de Abr. de 2017
You check your file's date for the row number 29 and 620..it is not correct. I think it should be corrected. Try the code with attached file.
3 comentarios
KSSV
el 12 de Abr. de 2017
prcp_hope = xlsread('NCEI_CDO.xls','Hope','G:G');
prcp_hope(prcp_hope == -9999) = NaN;
datem_hope = xlsread('NCEI_CDO.xls','Hope','F:F');
dates = datestr(datem_hope) ;
date = num2str(datem_hope) ;
date = strcat(date(:,1:4),'/',date(:,5:6),'/',date(:,6:end)) ;
thedatenum = datenum(date) ;
plot(thedatenum,prcp_hope)
datetick('x','yyyy/mm/dd')
Más respuestas (1)
Peter Perkins
el 12 de Abr. de 2017
Editada: Peter Perkins
el 12 de Abr. de 2017
If you are using a fairly recent version of MATLAB, use readtable, not xlsread. To make your life easier, you'll want to move those column headers in your Excel file to be above the data, not alongside the data. It looks like your dates are numbers of the form yyymmdd, so call datetime with 'Convert','yyyymmdd' to get a datetime variable in the table. Then just call plot with that datetime and whatever data you want to plot. Something like
>> t = readtable('NCEI_CDO.xls');
>> t.DATE = datetime(t.DATE,'ConvertFrom','yyyymmdd');
>> plot(t.DATE,t.PRCP);
except that you have some work to do between lines 2 and 3, because you have some dates that are in the 900's, rather than the 1900's, and some PRCP values that are -9999. There are simple tools like standardizeMissing to handle the latter.
Hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Calendar en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!