Why is the workspace not displaying values?

2 visualizzazioni (ultimi 30 giorni)
Hello everyone!
I am working on a boxplot code with maximum and minimum temperatures. For some reason, I am not getting anything in my DailyTMAX_1, DailyTMAX_2, DailyTMAX_3, etc... I just receive open brackets [ ]. The same is happening with some of my CSV files, but other ones do work. I do not know it it is something on my code or if it is the CSV data file. Hope anyone can help me with this.
This is part of the code:
StationRawData = readtable('Socorro.csv');
DateInfo = StationRawData.DATE;
%To find start and end date and add 1900s or 2000s (boxplot)
target = datetime("12/31/0099",'InputFormat','MM/dd/yyyy');
column=logical(DateInfo==target);
row=find(column) %row with last date from 1999
[year, month, day] = ymd(DateInfo);
year(1:row) = year(1:row) + 1900;
year(row+1:S(1)) = year(row+1:S(1)) + 2000;
DateInfo = datetime(year, month, day);
% For 30 year intervals (1930-1959)
upper_limit = datetime("12/31/1959",'InputFormat','MM/dd/yyyy');
lower_limit = datetime("1/1/1930",'InputFormat','MM/dd/yyyy');
column2=logical(DateInfo>lower_limit&DateInfo<upper_limit); %find dates between this range
row2=find(column2);
startrow=min(row2);
endrow=max(row2);
Datenumber = datenum(DateInfo(startrow:endrow));
YearlyPR_1 = StationRawData.PRCP(startrow:endrow);
DailyTMAX_1 = StationRawData.TMAX(startrow:endrow);
DailyTMIN_1 = StationRawData.TMIN(startrow:endrow);
hold on
x = [DailyTMAX_1; DailyTMAX_2; DailyTMAX_3];
g1 = repmat({'1931-1960'},10896,1);
g2 = repmat({'1961-1990'},10672,1);
g3 = repmat({'1991-2020'},6687,1);
g = [g1; g2; g3];
boxplot(x,g)
Thank you!

Risposta accettata

Walter Roberson
Walter Roberson il 21 Lug 2021
StationRawData = readtable('Socorro.csv');
when you use readtable() with a date that has a 2 digit year, then https://www.mathworks.com/help/matlab/ref/datetime.html#buhzxmk-1-Format
  • If you read a two-digit year number and specify the format as y or yy, then the pivot year determines the century to which the year belongs.
The default pivot year https://www.mathworks.com/help/matlab/ref/datetime.html#d123e286529 is year(datetime('now'))-50
So years given as 71 to 99 would be assigned as 1900, and 00 to 70 would be assigned to 2000.
Because of this, you would not have any datetimes in the 0099 range. You would have had to overridden the datetime parsing to use 'uu' instead of 'yy' to do the transformation that way.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by