現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How do I remove leap year data?
5 ビュー (過去 30 日間)
古いコメントを表示
The code works. However, I need to run eliminate all leap year data (February 29th) because March 1st and February 29th are getting mixed up in the outgoing text file. How can I do this? I have tried using braces around idxMn,2 and etc but received an error stating it's unable to use them. I also can't use leapyear for I do not have aerospace toolbox. Any help will be grateful.
close all;
clear all;
clc;
Datafiles = fileDatastore("temp_summary*.txt","ReadFcn",@readMonth,"UniformRead",true);
dataAll = readall(Datafiles)
dataAll.Year = year(dataAll.Day);
dataAll.Month = month(dataAll.Day);
dataAll.DD = day(dataAll.Day)
% Unstack variables
minT_tbl = unstack(dataAll,"MinT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
maxT_tbl = unstack(dataAll,"MaxT","Year","GroupingVariables", ["Month","DD"],"VariableNamingRule","preserve")
yrs =str2double(minT_tbl.Properties.VariableNames(3:end))';
% find min
[Tmin,idxMn] = min(minT_tbl{:,3:end},[],2,'omitnan');
Tmin_yr = yrs(eomday(idxMn,2),[]);
% find max
[Tmax,idxMx] = max(maxT_tbl{:,3:end},[],2,'omitnan');
Tmax_yr = yrs(eomday(idxMx,2),[]);
% find low high
[lowTMax,idxMx] = min(maxT_tbl{:,3:end},[],2,'omitnan');
LowTMax_yr = yrs(eomday(idxMx,2),[]);
% find high low
[highlowTMn,idxMn] = max(minT_tbl{:,3:end},[],2,'omitnan');
HighLowT_yr = yrs(eomday(idxMn,2),[]);
% find avg high
AvgTMx = round(mean(table2array(maxT_tbl(:,3:end)),2,'omitnan'));
% find avg low
AvgTMn = round(mean(table2array(minT_tbl(:,3:end)),2,'omitnan'));
% Results
tempTbl = [maxT_tbl(:,["Month","DD"]), table(Tmax,Tmax_yr,AvgTMx,lowTMax,LowTMax_yr,Tmin,Tmin_yr,AvgTMn,highlowTMn,HighLowT_yr)]
tempTbl2 = splitvars(tempTbl)
FID = fopen('Meda 05 Temperature Climatology.txt','w');
report_date = datetime('now','format','yyyy-MM-dd HH:MM');
fprintf(FID,'Meda 05 Temperature Climatology at %s \n', report_date);
fprintf(FID,"Month DD Temp Max (°F) Tmax_yr AvgTMax (°F) lowTMax (°F) LowTMax_yr TempMin (°F) TMin_yr AvgTMin (°F) HighlowTMin (°F) HighlowT_yr \n");
fprintf(FID,'%3d %6d %7d %14d %11d %11d %15d %11d %13d %10d %13d %17d \n', tempTbl2{:,1:end}');
fclose(FID);
winopen('Meda 05 Temperature Climatology.txt')
function Tbl = readMonth(filename)
opts = detectImportOptions(filename)
opts.ConsecutiveDelimitersRule = 'join';
opts.MissingRule = 'omitvar';
opts = setvartype(opts,'double');
opts.VariableNames = ["Day","MaxT","MinT","AvgT"];
Tbl = readtable(filename,opts);
Tbl = standardizeMissing(Tbl,{999,'N/A'},"DataVariables",{'MaxT','MinT','AvgT'})
Tbl = standardizeMissing(Tbl,{-99,'N/A'},"DataVariables",{'MaxT','MinT','AvgT'})
[~,basename] = fileparts(filename);
nameparts = regexp(basename, '\.', 'split');
dateparts = regexp(nameparts{end}, '_','split');
year_str = dateparts{end}
d = str2double(extract(filename,digitsPattern));
Tbl.Day = datetime(d(3),d(2),Tbl.Day)
end
1 件のコメント
Cris LaPierre
2024 年 2 月 8 日
This question is getting spread across several questions, so bringing my comments here.
You need to check if the month ends in 29 before you convert Day into a datetime. That conversion happens in readMonth. Since 2/29 gets convereted to 3/1 in non-leap year years, you need to identify this date before the converstion to datetime.
Normally this wouldn't be an issue, but for some reason your files contain data for Feb 29 even in non-leap year years.
dataAll = readtable('temp_summary.05.02_1981.txt',...
"ConsecutiveDelimitersRule","join","ReadVariableNames",false,...
"Delimiter",{' ','\t','*','#'},"LeadingDelimitersRule",'ignore',...
'EmptyLineRule','skip');
dataAll.Properties.VariableNames = {'Day' 'MaxT' 'MinT' 'AvgT'};
dataAll.Day = datetime(1981,2,dataAll.Day); % 1981, which is a non-leap year
dataAll.Month = month(dataAll.Day);
dataAll.DD = day(dataAll.Day);
tail(dataAll)
% Remove all Feb 29 dates from the table
LY = (dataAll.Month(:)== 2 & dataAll.DD(:) == 29);
dataAll(LY,:) = [ ];
tail(dataAll)
As you can see, the current LY code did not remove the data. This is because 2/29 is converted to 3/1 by datetime. You need to perform your LY correction before you convert to datetime.
dataAll2 = readtable('temp_summary.05.02_1981.txt',...
"ConsecutiveDelimitersRule","join","ReadVariableNames",false,...
"Delimiter",{' ','\t','*','#'},"LeadingDelimitersRule",'ignore',...
'EmptyLineRule','skip');
dataAll2.Properties.VariableNames = {'Day' 'MaxT' 'MinT' 'AvgT'};
tail(dataAll2)
% If the last date of the imported month is 29, delete
if dataAll2.Day(end==29)
dataAll2(end,:)=[];
end
% Now you can convert Day to datetime
dataAll2.Day = datetime(1981,2,dataAll2.Day); % 1981, which is a non-leap year
dataAll2.Month = month(dataAll2.Day);
dataAll2.DD = day(dataAll2.Day);
tail(dataAll2)
Now there is no 3/1 data in the Feb 1981 table
Since you are using a datastore to load you files, you must make this edit in your read function.
採用された回答
Star Strider
2024 年 2 月 5 日
I ran your code with the provided data (here, online), however I do not see any leap year days.
That aside, something like this could work —
DateTime = datetime(2024,02,25) + caldays(0:11).'
DateTime = 12×1 datetime array
25-Feb-2024
26-Feb-2024
27-Feb-2024
28-Feb-2024
29-Feb-2024
01-Mar-2024
02-Mar-2024
03-Mar-2024
04-Mar-2024
05-Mar-2024
06-Mar-2024
07-Mar-2024
DateTime(month(DateTime) == 2 & day(DateTime) == 29) = []
DateTime = 11×1 datetime array
25-Feb-2024
26-Feb-2024
27-Feb-2024
28-Feb-2024
01-Mar-2024
02-Mar-2024
03-Mar-2024
04-Mar-2024
05-Mar-2024
06-Mar-2024
07-Mar-2024
This year happens to be a leap year, however this approach is not sensitive to the year, since it just searches for and eliminates every February 29 entry.
.
16 件のコメント
Jonathon Klepatzki
2024 年 2 月 5 日
dataAll(month(dataAll.Month) == 2 & day(dataAll.DD) == 29)=[];
Error, "check for missing argument or incorrect argument data type in call to function 'month'
The rest of the code is the same.
Star Strider
2024 年 2 月 5 日
I had serious problems understanding the data your code produces.
Perhaps this instead:
dataAll(dataAll.Month == 2 & dataAll.Day == 29)=[];
If you have already isolated the month numbers and day numbers in other variables, using the month and day functions as I do in my example is probably not going to add anything, and in this instance, throws errors.
Testing that variation here, and changing my code to match your data —
dataAll = datetime(2024,02,25) + caldays(0:11).'
dataAll = 12×1 datetime array
25-Feb-2024
26-Feb-2024
27-Feb-2024
28-Feb-2024
29-Feb-2024
01-Mar-2024
02-Mar-2024
03-Mar-2024
04-Mar-2024
05-Mar-2024
06-Mar-2024
07-Mar-2024
dataAll.Month = month(dataAll);
dataAll.Day = day(dataAll);
dataAll(dataAll.Month == 2 & dataAll.Day == 29)=[]
dataAll = 11×1 datetime array
25-Feb-2024
26-Feb-2024
27-Feb-2024
28-Feb-2024
01-Mar-2024
02-Mar-2024
03-Mar-2024
04-Mar-2024
05-Mar-2024
06-Mar-2024
07-Mar-2024
That seems to work, although it differs from your posted code, so consider checking that. (I removed some of the semicolons to display the results. Add them back in your code.)
.
Jonathon Klepatzki
2024 年 2 月 5 日
I just tried the method you prescribed and got another error. Are you using 2020b or 2023?
Star Strider
2024 年 2 月 5 日
I’m running R2023b, however that shouldn’t make a difference with datetime arrays, since I don’t believe there were any significant changes from R2020a to R2023b releases.
What error are you getting? Please copy the entire error message (all the red text from your Command Window) and paste it to a new Comment or an edited previous Comment here.
Star Strider
2024 年 2 月 5 日
That does not make sense to me, because the code extracts numbers (the month number and the day number) and then compares them. to double constants (2 and 29 respectively). There is no comparison between datetime variables and double variables.
One problem is that none of those years are leap years, if I am parsing the file names correctly, so datetime is assigning the 29-Feb as 1-Mar. The datetime function checks for that and assigns the dates appropriately to the months. (This is one of its strengths, in my opinion.)
If I assign the year as this year (a leap year), then my code works —
files = dir('*.txt');
for k = 1:numel(files)
filename = files(k).name
T{k} = readtable(files(k).name);
nrows = size(T{k},1);
Nr = regexp(filename,'\d*','match');
Check = eomday(cellfun(@str2double,Nr(3)),2) % Check 'filename' Year For Leap Year
Nr{3} = '2024'; % Artificially Assign Leap Year To Test Code
Yr = cellfun(@str2double,repmat(Nr(3),nrows,1));
Mo = cellfun(@str2double,repmat(Nr(2),nrows,1));
T{k}.DateTime = datetime(Yr,Mo,T{k}{:,1});
end
filename = 'temp_summary.05.02_1981.txt'
Check = 28
filename = 'temp_summary.05.02_1982.txt'
Check = 28
filename = 'temp_summary.05.03_1981.txt'
Check = 28
filename = 'temp_summary.05.03_1982.txt'
Check = 28
T{:}
ans = 29×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 57 12 34.5 NaN 01-Feb-2024
2 58 19 38.5 NaN 02-Feb-2024
3 59 17 37 NaN 03-Feb-2024
4 59 12 35.5 NaN 04-Feb-2024
5 50 12 NaN 31.5 05-Feb-2024
6 54 31 42.5 NaN 06-Feb-2024
7 60 13 36.5 NaN 07-Feb-2024
8 51 29 40 NaN 08-Feb-2024
9 52 36 44 NaN 09-Feb-2024
10 59 24 41.5 NaN 10-Feb-2024
11 61 36 48.5 NaN 11-Feb-2024
12 67 28 46.5 NaN 12-Feb-2024
13 63 21 42 NaN 13-Feb-2024
14 63 29 46 NaN 14-Feb-2024
15 70 26 47 NaN 15-Feb-2024
16 72 29 51.5 NaN 16-Feb-2024
ans = 29×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 51 32 42.5 NaN 01-Feb-2024
2 52 24 39 NaN 02-Feb-2024
3 59 23 40 NaN 03-Feb-2024
4 45 27 37 NaN 04-Feb-2024
5 41 16 28.5 NaN 05-Feb-2024
6 48 10 28 NaN 06-Feb-2024
7 48 8 NaN 27 07-Feb-2024
8 52 20 36 NaN 08-Feb-2024
9 50 19 33.5 NaN 09-Feb-2024
10 35 30 33.5 NaN 10-Feb-2024
11 54 31 42.5 NaN 11-Feb-2024
12 56 27 40.5 NaN 12-Feb-2024
13 60 27 43.5 NaN 13-Feb-2024
14 63 35 48 NaN 14-Feb-2024
15 66 31 47.5 NaN 15-Feb-2024
16 70 40 56 NaN 16-Feb-2024
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 60 30 46 NaN 01-Mar-2024
2 59 27 42 NaN 02-Mar-2024
3 59 21 NaN 39 03-Mar-2024
4 56 38 47 NaN 04-Mar-2024
5 59 23 42 NaN 05-Mar-2024
6 64 21 42.5 NaN 06-Mar-2024
7 67 34 50.5 NaN 07-Mar-2024
8 69 28 47.5 NaN 08-Mar-2024
9 69 47 57 NaN 09-Mar-2024
10 64 51 58.5 NaN 10-Mar-2024
11 69 40 54.5 NaN 11-Mar-2024
12 70 NaN 30 51 12-Mar-2024
13 61 40 50.5 NaN 13-Mar-2024
14 57 43 49 NaN 14-Mar-2024
15 49 40 44.5 NaN 15-Mar-2024
16 45 36 39.5 NaN 16-Mar-2024
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 44 35 40.5 NaN 01-Mar-2024
2 61 31 46 NaN 02-Mar-2024
3 59 24 42 NaN 03-Mar-2024
4 50 43 45.5 NaN 04-Mar-2024
5 51 38 44.5 NaN 05-Mar-2024
6 55 38 46.5 NaN 06-Mar-2024
7 66 28 47 NaN 07-Mar-2024
8 66 32 48 NaN 08-Mar-2024
9 66 27 47.5 NaN 09-Mar-2024
10 62 30 47 NaN 10-Mar-2024
11 66 36 51 NaN 11-Mar-2024
12 55 35 45 NaN 12-Mar-2024
13 60 21 NaN 41.5 13-Mar-2024
14 66 27 46.5 NaN 14-Mar-2024
15 71 38 53 NaN 15-Mar-2024
16 63 40 51.5 NaN 16-Mar-2024
for k = 1:numel(T) % Loop To Remove 29-Feb
Lv = (month(T{k}.DateTime) == 2) & (day(T{k}.DateTime) == 29);
T{k}(Lv,:) = [];
end
T{:}
ans = 28×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 57 12 34.5 NaN 01-Feb-2024
2 58 19 38.5 NaN 02-Feb-2024
3 59 17 37 NaN 03-Feb-2024
4 59 12 35.5 NaN 04-Feb-2024
5 50 12 NaN 31.5 05-Feb-2024
6 54 31 42.5 NaN 06-Feb-2024
7 60 13 36.5 NaN 07-Feb-2024
8 51 29 40 NaN 08-Feb-2024
9 52 36 44 NaN 09-Feb-2024
10 59 24 41.5 NaN 10-Feb-2024
11 61 36 48.5 NaN 11-Feb-2024
12 67 28 46.5 NaN 12-Feb-2024
13 63 21 42 NaN 13-Feb-2024
14 63 29 46 NaN 14-Feb-2024
15 70 26 47 NaN 15-Feb-2024
16 72 29 51.5 NaN 16-Feb-2024
ans = 28×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 51 32 42.5 NaN 01-Feb-2024
2 52 24 39 NaN 02-Feb-2024
3 59 23 40 NaN 03-Feb-2024
4 45 27 37 NaN 04-Feb-2024
5 41 16 28.5 NaN 05-Feb-2024
6 48 10 28 NaN 06-Feb-2024
7 48 8 NaN 27 07-Feb-2024
8 52 20 36 NaN 08-Feb-2024
9 50 19 33.5 NaN 09-Feb-2024
10 35 30 33.5 NaN 10-Feb-2024
11 54 31 42.5 NaN 11-Feb-2024
12 56 27 40.5 NaN 12-Feb-2024
13 60 27 43.5 NaN 13-Feb-2024
14 63 35 48 NaN 14-Feb-2024
15 66 31 47.5 NaN 15-Feb-2024
16 70 40 56 NaN 16-Feb-2024
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 60 30 46 NaN 01-Mar-2024
2 59 27 42 NaN 02-Mar-2024
3 59 21 NaN 39 03-Mar-2024
4 56 38 47 NaN 04-Mar-2024
5 59 23 42 NaN 05-Mar-2024
6 64 21 42.5 NaN 06-Mar-2024
7 67 34 50.5 NaN 07-Mar-2024
8 69 28 47.5 NaN 08-Mar-2024
9 69 47 57 NaN 09-Mar-2024
10 64 51 58.5 NaN 10-Mar-2024
11 69 40 54.5 NaN 11-Mar-2024
12 70 NaN 30 51 12-Mar-2024
13 61 40 50.5 NaN 13-Mar-2024
14 57 43 49 NaN 14-Mar-2024
15 49 40 44.5 NaN 15-Mar-2024
16 45 36 39.5 NaN 16-Mar-2024
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 44 35 40.5 NaN 01-Mar-2024
2 61 31 46 NaN 02-Mar-2024
3 59 24 42 NaN 03-Mar-2024
4 50 43 45.5 NaN 04-Mar-2024
5 51 38 44.5 NaN 05-Mar-2024
6 55 38 46.5 NaN 06-Mar-2024
7 66 28 47 NaN 07-Mar-2024
8 66 32 48 NaN 08-Mar-2024
9 66 27 47.5 NaN 09-Mar-2024
10 62 30 47 NaN 10-Mar-2024
11 66 36 51 NaN 11-Mar-2024
12 55 35 45 NaN 12-Mar-2024
13 60 21 NaN 41.5 13-Mar-2024
14 66 27 46.5 NaN 14-Mar-2024
15 71 38 53 NaN 15-Mar-2024
16 63 40 51.5 NaN 16-Mar-2024
The problem may be that the years in the file names are wrong. There is no way I can correct for that.
.
Jonathon Klepatzki
2024 年 2 月 5 日
I was able to figure out the code necessary to remove the LY. See below. Thank you for helping me today!
LY = (dataAll.Month(:)==2 & dataAll.DD(:)==29);
dataAll(LY,:) = [ ];
Jonathon Klepatzki
2024 年 2 月 7 日
It turns out, the code in my previous comment only deletes "2" and "29" thus, month does not equal to 2 nor does it have 29. But the data still remains. Any suggestions?
Star Strider
2024 年 2 月 7 日
‘Any suggestions?’
Yes. It is difficult for me to follow what you are doing. See if you can incorporate elements of my code here into yours.
This works —
files = dir('*.txt');
for k = 1:numel(files)
filename = files(k).name
T{k} = readtable(filename);
fn{k} = filename;
nrows = size(T{k},1);
Nr = regexp(filename,'\d*','match');
% Check = eomday(cellfun(@str2double,Nr(3)),2) % Check 'filename' Year For Leap Year
% Nr{3} = '2024'; % Artificially Assign Leap Year To Test Code
Yr = cellfun(@str2double,repmat(Nr(3),nrows,1));
Mo = cellfun(@str2double,repmat(Nr(2),nrows,1));
T{k}.DateTime = datetime(Yr,Mo,T{k}{:,1});
end
filename = 'temp_summary.05.02_2016.txt'
filename = 'temp_summary.05.03_2016.txt'
T{:}
ans = 29x6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 40 27 35.6 NaN 01-Feb-2016
2 40 20 29.1 NaN 02-Feb-2016
3 44 18 NaN 29.9 03-Feb-2016
4 50 22 35.6 NaN 04-Feb-2016
5 55 22 37.8 NaN 05-Feb-2016
6 59 22 39.5 NaN 06-Feb-2016
7 64 23 44.4 NaN 07-Feb-2016
8 69 34 49.8 NaN 08-Feb-2016
9 72 29 50 NaN 09-Feb-2016
10 72 25 46.8 NaN 10-Feb-2016
11 73 24 46 NaN 11-Feb-2016
12 69 22 44.4 NaN 12-Feb-2016
13 73 24 46.1 NaN 13-Feb-2016
14 68 26 47.3 NaN 14-Feb-2016
15 72 30 52.2 NaN 15-Feb-2016
16 75 NaN 29 50.4 16-Feb-2016
ans = 31x6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 77 33 54 NaN 01-Mar-2016
2 76 32 52.6 NaN 02-Mar-2016
3 78 30 52.7 NaN 03-Mar-2016
4 71 35 51.5 NaN 04-Mar-2016
5 74 29 53 NaN 05-Mar-2016
6 68 41 57.8 NaN 06-Mar-2016
7 60 30 50.7 NaN 07-Mar-2016
8 47 27 37.2 NaN 08-Mar-2016
9 63 22 NaN 44.9 09-Mar-2016
10 67 29 49.7 NaN 10-Mar-2016
11 76 27 53.5 NaN 11-Mar-2016
12 72 38 56.6 NaN 12-Mar-2016
13 60 38 48.4 NaN 13-Mar-2016
14 61 28 48.1 NaN 14-Mar-2016
15 66 35 52.6 NaN 15-Mar-2016
16 71 25 48.3 NaN 16-Mar-2016
for k = 1:numel(T) % Loop To Remove 29-Feb
Lv = (month(T{k}.DateTime) == 2) & (day(T{k}.DateTime) == 29);
T{k}(Lv,:) = [];
if nnz(Lv) % Optional 'if' Block
fprintf('Feb 29 removed from %s\n', fn{k})
end
end
Feb 29 removed from temp_summary.05.02_2016.txt
T{:}
ans = 28x6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 40 27 35.6 NaN 01-Feb-2016
2 40 20 29.1 NaN 02-Feb-2016
3 44 18 NaN 29.9 03-Feb-2016
4 50 22 35.6 NaN 04-Feb-2016
5 55 22 37.8 NaN 05-Feb-2016
6 59 22 39.5 NaN 06-Feb-2016
7 64 23 44.4 NaN 07-Feb-2016
8 69 34 49.8 NaN 08-Feb-2016
9 72 29 50 NaN 09-Feb-2016
10 72 25 46.8 NaN 10-Feb-2016
11 73 24 46 NaN 11-Feb-2016
12 69 22 44.4 NaN 12-Feb-2016
13 73 24 46.1 NaN 13-Feb-2016
14 68 26 47.3 NaN 14-Feb-2016
15 72 30 52.2 NaN 15-Feb-2016
16 75 NaN 29 50.4 16-Feb-2016
ans = 31x6 table
Var1 Var2 Var3 Var4 Var5 DateTime
____ ____ ____ ____ ____ ___________
1 77 33 54 NaN 01-Mar-2016
2 76 32 52.6 NaN 02-Mar-2016
3 78 30 52.7 NaN 03-Mar-2016
4 71 35 51.5 NaN 04-Mar-2016
5 74 29 53 NaN 05-Mar-2016
6 68 41 57.8 NaN 06-Mar-2016
7 60 30 50.7 NaN 07-Mar-2016
8 47 27 37.2 NaN 08-Mar-2016
9 63 22 NaN 44.9 09-Mar-2016
10 67 29 49.7 NaN 10-Mar-2016
11 76 27 53.5 NaN 11-Mar-2016
12 72 38 56.6 NaN 12-Mar-2016
13 60 38 48.4 NaN 13-Mar-2016
14 61 28 48.1 NaN 14-Mar-2016
15 66 35 52.6 NaN 15-Mar-2016
16 71 25 48.3 NaN 16-Mar-2016
Alternatively, it may be necessary for you to use my code example here to pre-process your data. Then save the resulting tables (each with a slightly different name so you will not overwrite the original files) and use them instead. That is the easiest approach I can suggest.
It is likely necessary to create a datetime variable in order to do this. (The first for loop in my code does this. It is likely straightforward for you to adapt it to use in your code.) That may seem superfluous, however using the datetime function to create a relevant date array actually makes this easier.
.
Jonathon Klepatzki
2024 年 2 月 7 日
the goal is for me to eliminate all data that corresponds to February 29th. I didn't realize this, but despite certain dates not being a LY, all Februarys has a 29th.
When I tried it my way earlier, it turns out that March 1st is blending with the data of February 29th. Thus making the data, incredibly wrong for the 1st of March.
Star Strider
2024 年 2 月 7 日
We may need to be something different, then, if all Februaries have a 29th. That is not normal, and datetime will only work correctly for Februaries in leap years in that instance.
This version creates a new ‘YMD’ variable to replace the datetime call, and then scans ‘YMD’ for all instances of ‘Feb 29’ and removes them, leaving intact all the other months. I used all of your uploaded files to test this.
Try this —
files = dir('*.txt');
for k = 1:numel(files)
filename = files(k).name
T{k,:} = readtable(filename);
fn{k,:} = filename;
nrows = size(T{k},1);
Nr = regexp(filename,'\d*','match');
% Check = eomday(cellfun(@str2double,Nr(3)),2) % Check 'filename' Year For Leap Year
% Nr{3} = '2024'; % Artificially Assign Leap Year To Test Code
Yr = cellfun(@str2double,repmat(Nr(3),nrows,1));
Mo = cellfun(@str2double,repmat(Nr(2),nrows,1));
% T{k}.DateTime = datetime(Yr,Mo,T{k}{:,1});
T{k}.YMD = [Yr Mo T{k}{:,1}]; % Create Variable To Replace ''datetime'
end
filename = 'temp_summary.05.02_1981.txt'
filename = 'temp_summary.05.02_1982.txt'
filename = 'temp_summary.05.02_2016.txt'
filename = 'temp_summary.05.03_1981.txt'
filename = 'temp_summary.05.03_1982.txt'
filename = 'temp_summary.05.03_2016.txt'
T{:}
ans = 29×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 57 12 34.5 NaN 1981 2 1
2 58 19 38.5 NaN 1981 2 2
3 59 17 37 NaN 1981 2 3
4 59 12 35.5 NaN 1981 2 4
5 50 12 NaN 31.5 1981 2 5
6 54 31 42.5 NaN 1981 2 6
7 60 13 36.5 NaN 1981 2 7
8 51 29 40 NaN 1981 2 8
9 52 36 44 NaN 1981 2 9
10 59 24 41.5 NaN 1981 2 10
11 61 36 48.5 NaN 1981 2 11
12 67 28 46.5 NaN 1981 2 12
13 63 21 42 NaN 1981 2 13
14 63 29 46 NaN 1981 2 14
15 70 26 47 NaN 1981 2 15
16 72 29 51.5 NaN 1981 2 16
ans = 29×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 51 32 42.5 NaN 1982 2 1
2 52 24 39 NaN 1982 2 2
3 59 23 40 NaN 1982 2 3
4 45 27 37 NaN 1982 2 4
5 41 16 28.5 NaN 1982 2 5
6 48 10 28 NaN 1982 2 6
7 48 8 NaN 27 1982 2 7
8 52 20 36 NaN 1982 2 8
9 50 19 33.5 NaN 1982 2 9
10 35 30 33.5 NaN 1982 2 10
11 54 31 42.5 NaN 1982 2 11
12 56 27 40.5 NaN 1982 2 12
13 60 27 43.5 NaN 1982 2 13
14 63 35 48 NaN 1982 2 14
15 66 31 47.5 NaN 1982 2 15
16 70 40 56 NaN 1982 2 16
ans = 29×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 40 27 35.6 NaN 2016 2 1
2 40 20 29.1 NaN 2016 2 2
3 44 18 NaN 29.9 2016 2 3
4 50 22 35.6 NaN 2016 2 4
5 55 22 37.8 NaN 2016 2 5
6 59 22 39.5 NaN 2016 2 6
7 64 23 44.4 NaN 2016 2 7
8 69 34 49.8 NaN 2016 2 8
9 72 29 50 NaN 2016 2 9
10 72 25 46.8 NaN 2016 2 10
11 73 24 46 NaN 2016 2 11
12 69 22 44.4 NaN 2016 2 12
13 73 24 46.1 NaN 2016 2 13
14 68 26 47.3 NaN 2016 2 14
15 72 30 52.2 NaN 2016 2 15
16 75 NaN 29 50.4 2016 2 16
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 60 30 46 NaN 1981 3 1
2 59 27 42 NaN 1981 3 2
3 59 21 NaN 39 1981 3 3
4 56 38 47 NaN 1981 3 4
5 59 23 42 NaN 1981 3 5
6 64 21 42.5 NaN 1981 3 6
7 67 34 50.5 NaN 1981 3 7
8 69 28 47.5 NaN 1981 3 8
9 69 47 57 NaN 1981 3 9
10 64 51 58.5 NaN 1981 3 10
11 69 40 54.5 NaN 1981 3 11
12 70 NaN 30 51 1981 3 12
13 61 40 50.5 NaN 1981 3 13
14 57 43 49 NaN 1981 3 14
15 49 40 44.5 NaN 1981 3 15
16 45 36 39.5 NaN 1981 3 16
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 44 35 40.5 NaN 1982 3 1
2 61 31 46 NaN 1982 3 2
3 59 24 42 NaN 1982 3 3
4 50 43 45.5 NaN 1982 3 4
5 51 38 44.5 NaN 1982 3 5
6 55 38 46.5 NaN 1982 3 6
7 66 28 47 NaN 1982 3 7
8 66 32 48 NaN 1982 3 8
9 66 27 47.5 NaN 1982 3 9
10 62 30 47 NaN 1982 3 10
11 66 36 51 NaN 1982 3 11
12 55 35 45 NaN 1982 3 12
13 60 21 NaN 41.5 1982 3 13
14 66 27 46.5 NaN 1982 3 14
15 71 38 53 NaN 1982 3 15
16 63 40 51.5 NaN 1982 3 16
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 77 33 54 NaN 2016 3 1
2 76 32 52.6 NaN 2016 3 2
3 78 30 52.7 NaN 2016 3 3
4 71 35 51.5 NaN 2016 3 4
5 74 29 53 NaN 2016 3 5
6 68 41 57.8 NaN 2016 3 6
7 60 30 50.7 NaN 2016 3 7
8 47 27 37.2 NaN 2016 3 8
9 63 22 NaN 44.9 2016 3 9
10 67 29 49.7 NaN 2016 3 10
11 76 27 53.5 NaN 2016 3 11
12 72 38 56.6 NaN 2016 3 12
13 60 38 48.4 NaN 2016 3 13
14 61 28 48.1 NaN 2016 3 14
15 66 35 52.6 NaN 2016 3 15
16 71 25 48.3 NaN 2016 3 16
for k = 1:numel(T) % Loop To Remove 29-Feb
Lv = (T{k}.YMD(:,2) == 2) & (T{k}.YMD(:,3) == 29);
T{k}(Lv,:) = [];
if nnz(Lv) % Optional 'if' Block
fprintf('Feb 29 removed from %s\n', fn{k})
end
end
Feb 29 removed from temp_summary.05.02_1981.txt
Feb 29 removed from temp_summary.05.02_1982.txt
Feb 29 removed from temp_summary.05.02_2016.txt
T{:}
ans = 28×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 57 12 34.5 NaN 1981 2 1
2 58 19 38.5 NaN 1981 2 2
3 59 17 37 NaN 1981 2 3
4 59 12 35.5 NaN 1981 2 4
5 50 12 NaN 31.5 1981 2 5
6 54 31 42.5 NaN 1981 2 6
7 60 13 36.5 NaN 1981 2 7
8 51 29 40 NaN 1981 2 8
9 52 36 44 NaN 1981 2 9
10 59 24 41.5 NaN 1981 2 10
11 61 36 48.5 NaN 1981 2 11
12 67 28 46.5 NaN 1981 2 12
13 63 21 42 NaN 1981 2 13
14 63 29 46 NaN 1981 2 14
15 70 26 47 NaN 1981 2 15
16 72 29 51.5 NaN 1981 2 16
ans = 28×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 51 32 42.5 NaN 1982 2 1
2 52 24 39 NaN 1982 2 2
3 59 23 40 NaN 1982 2 3
4 45 27 37 NaN 1982 2 4
5 41 16 28.5 NaN 1982 2 5
6 48 10 28 NaN 1982 2 6
7 48 8 NaN 27 1982 2 7
8 52 20 36 NaN 1982 2 8
9 50 19 33.5 NaN 1982 2 9
10 35 30 33.5 NaN 1982 2 10
11 54 31 42.5 NaN 1982 2 11
12 56 27 40.5 NaN 1982 2 12
13 60 27 43.5 NaN 1982 2 13
14 63 35 48 NaN 1982 2 14
15 66 31 47.5 NaN 1982 2 15
16 70 40 56 NaN 1982 2 16
ans = 28×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 40 27 35.6 NaN 2016 2 1
2 40 20 29.1 NaN 2016 2 2
3 44 18 NaN 29.9 2016 2 3
4 50 22 35.6 NaN 2016 2 4
5 55 22 37.8 NaN 2016 2 5
6 59 22 39.5 NaN 2016 2 6
7 64 23 44.4 NaN 2016 2 7
8 69 34 49.8 NaN 2016 2 8
9 72 29 50 NaN 2016 2 9
10 72 25 46.8 NaN 2016 2 10
11 73 24 46 NaN 2016 2 11
12 69 22 44.4 NaN 2016 2 12
13 73 24 46.1 NaN 2016 2 13
14 68 26 47.3 NaN 2016 2 14
15 72 30 52.2 NaN 2016 2 15
16 75 NaN 29 50.4 2016 2 16
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 60 30 46 NaN 1981 3 1
2 59 27 42 NaN 1981 3 2
3 59 21 NaN 39 1981 3 3
4 56 38 47 NaN 1981 3 4
5 59 23 42 NaN 1981 3 5
6 64 21 42.5 NaN 1981 3 6
7 67 34 50.5 NaN 1981 3 7
8 69 28 47.5 NaN 1981 3 8
9 69 47 57 NaN 1981 3 9
10 64 51 58.5 NaN 1981 3 10
11 69 40 54.5 NaN 1981 3 11
12 70 NaN 30 51 1981 3 12
13 61 40 50.5 NaN 1981 3 13
14 57 43 49 NaN 1981 3 14
15 49 40 44.5 NaN 1981 3 15
16 45 36 39.5 NaN 1981 3 16
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 44 35 40.5 NaN 1982 3 1
2 61 31 46 NaN 1982 3 2
3 59 24 42 NaN 1982 3 3
4 50 43 45.5 NaN 1982 3 4
5 51 38 44.5 NaN 1982 3 5
6 55 38 46.5 NaN 1982 3 6
7 66 28 47 NaN 1982 3 7
8 66 32 48 NaN 1982 3 8
9 66 27 47.5 NaN 1982 3 9
10 62 30 47 NaN 1982 3 10
11 66 36 51 NaN 1982 3 11
12 55 35 45 NaN 1982 3 12
13 60 21 NaN 41.5 1982 3 13
14 66 27 46.5 NaN 1982 3 14
15 71 38 53 NaN 1982 3 15
16 63 40 51.5 NaN 1982 3 16
ans = 31×6 table
Var1 Var2 Var3 Var4 Var5 YMD
____ ____ ____ ____ ____ ____________________
1 77 33 54 NaN 2016 3 1
2 76 32 52.6 NaN 2016 3 2
3 78 30 52.7 NaN 2016 3 3
4 71 35 51.5 NaN 2016 3 4
5 74 29 53 NaN 2016 3 5
6 68 41 57.8 NaN 2016 3 6
7 60 30 50.7 NaN 2016 3 7
8 47 27 37.2 NaN 2016 3 8
9 63 22 NaN 44.9 2016 3 9
10 67 29 49.7 NaN 2016 3 10
11 76 27 53.5 NaN 2016 3 11
12 72 38 56.6 NaN 2016 3 12
13 60 38 48.4 NaN 2016 3 13
14 61 28 48.1 NaN 2016 3 14
15 66 35 52.6 NaN 2016 3 15
16 71 25 48.3 NaN 2016 3 16
I would still suggest using this as a preprocessing step, saving all the processed files by slightly different names from the originals, and then working with them instead of the originals.
.
Star Strider
2024 年 2 月 8 日
I saw your other question and decided to see if I could incorporate an answer to it in my code.
Without changing my original code too much, I was able to recover the variable names and elimiinate the '*' and '#' characters. I also changed it to delete 29 Feb from only the non-leap years.
The code —
files = dir('*.txt');
for k = 1:numel(files)
filename = files(k).name
Tx = fileread(files(k).name);
VN = regexp(Tx(1,:), '(\s\s)|(\s\s\s)', 'split');
VN = cellfun(@strtrim,VN(2:5), 'Unif',0);
opts = detectImportOptions(files(1).name);
opts = setvartype(opts,{'Var2','Var3','Var4'},'char');
T{k,:} = readtable(filename, opts);
LLv1 = any(ismember(T{k}{:,4},{'*'}),2);
T{k}{LLv1,4} = {num2str(T{k}{LLv1,5},'%.1f')};
LLv2 = any(ismember(T{k}{:,3},{'#'}),2);
T{k}{LLv2,3:4} = [T{k}{LLv2,4},{num2str(T{k}{LLv2,5},'%.1f')}];
T{k} = T{k}(:,1:end-1);
T{k}.Properties.VariableNames = VN;
T{k}{:,2:4} = cellfun(@str2double,T{k}{:,2:4}, 'Unif',0);
Te = array2table([T{k}{:,1} cell2mat(T{k}{:,2:4})], 'VariableNames',VN);
T{k} = Te;
% T{k}
fn{k,:} = filename;
nrows = size(T{k},1);
Nr = regexp(filename,'\d*','match');
% Check = eomday(cellfun(@str2double,Nr(3)),2) % Check 'filename' Year For Leap Year
% Nr{3} = '2024'; % Artificially Assign Leap Year To Test Code
Yr = cellfun(@str2double,repmat(Nr(3),nrows,1));
Mo = cellfun(@str2double,repmat(Nr(2),nrows,1));
% T{k}.DateTime = datetime(Yr,Mo,T{k}{:,1});
T{k}.YMD = [Yr Mo T{k}{:,1}]; % Create Variable To Replace ''datetime'
end
filename = 'temp_summary.05.02_1981.txt'
filename = 'temp_summary.05.02_1982.txt'
filename = 'temp_summary.05.02_2016.txt'
filename = 'temp_summary.05.03_1981.txt'
filename = 'temp_summary.05.03_1982.txt'
filename = 'temp_summary.05.03_2016.txt'
T{:}
ans = 29x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 57 12 34.5 1981 2 1
2 58 19 38.5 1981 2 2
3 59 17 37 1981 2 3
4 59 12 35.5 1981 2 4
5 50 12 31.5 1981 2 5
6 54 31 42.5 1981 2 6
7 60 13 36.5 1981 2 7
8 51 29 40 1981 2 8
9 52 36 44 1981 2 9
10 59 24 41.5 1981 2 10
11 61 36 48.5 1981 2 11
12 67 28 46.5 1981 2 12
13 63 21 42 1981 2 13
14 63 29 46 1981 2 14
15 70 26 47 1981 2 15
16 72 29 51.5 1981 2 16
ans = 29x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 51 32 42.5 1982 2 1
2 52 24 39 1982 2 2
3 59 23 40 1982 2 3
4 45 27 37 1982 2 4
5 41 16 28.5 1982 2 5
6 48 10 28 1982 2 6
7 48 8 27 1982 2 7
8 52 20 36 1982 2 8
9 50 19 33.5 1982 2 9
10 35 30 33.5 1982 2 10
11 54 31 42.5 1982 2 11
12 56 27 40.5 1982 2 12
13 60 27 43.5 1982 2 13
14 63 35 48 1982 2 14
15 66 31 47.5 1982 2 15
16 70 40 56 1982 2 16
ans = 29x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 40 27 35.6 2016 2 1
2 40 20 29.1 2016 2 2
3 44 18 29.9 2016 2 3
4 50 22 35.6 2016 2 4
5 55 22 37.8 2016 2 5
6 59 22 39.5 2016 2 6
7 64 23 44.4 2016 2 7
8 69 34 49.8 2016 2 8
9 72 29 50 2016 2 9
10 72 25 46.8 2016 2 10
11 73 24 46 2016 2 11
12 69 22 44.4 2016 2 12
13 73 24 46.1 2016 2 13
14 68 26 47.3 2016 2 14
15 72 30 52.2 2016 2 15
16 75 29 50.4 2016 2 16
ans = 31x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 60 30 46 1981 3 1
2 59 27 42 1981 3 2
3 59 21 39 1981 3 3
4 56 38 47 1981 3 4
5 59 23 42 1981 3 5
6 64 21 42.5 1981 3 6
7 67 34 50.5 1981 3 7
8 69 28 47.5 1981 3 8
9 69 47 57 1981 3 9
10 64 51 58.5 1981 3 10
11 69 40 54.5 1981 3 11
12 70 30 51 1981 3 12
13 61 40 50.5 1981 3 13
14 57 43 49 1981 3 14
15 49 40 44.5 1981 3 15
16 45 36 39.5 1981 3 16
ans = 31x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 44 35 40.5 1982 3 1
2 61 31 46 1982 3 2
3 59 24 42 1982 3 3
4 50 43 45.5 1982 3 4
5 51 38 44.5 1982 3 5
6 55 38 46.5 1982 3 6
7 66 28 47 1982 3 7
8 66 32 48 1982 3 8
9 66 27 47.5 1982 3 9
10 62 30 47 1982 3 10
11 66 36 51 1982 3 11
12 55 35 45 1982 3 12
13 60 21 41.5 1982 3 13
14 66 27 46.5 1982 3 14
15 71 38 53 1982 3 15
16 63 40 51.5 1982 3 16
ans = 31x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 77 33 54 2016 3 1
2 76 32 52.6 2016 3 2
3 78 30 52.7 2016 3 3
4 71 35 51.5 2016 3 4
5 74 29 53 2016 3 5
6 68 41 57.8 2016 3 6
7 60 30 50.7 2016 3 7
8 47 27 37.2 2016 3 8
9 63 22 44.9 2016 3 9
10 67 29 49.7 2016 3 10
11 76 27 53.5 2016 3 11
12 72 38 56.6 2016 3 12
13 60 38 48.4 2016 3 13
14 61 28 48.1 2016 3 14
15 66 35 52.6 2016 3 15
16 71 25 48.3 2016 3 16
for k = 1:numel(T) % Loop To Remove 29-Feb
if eomday(T{k}.YMD(:,1), 2) ~= 29
Lv = (T{k}.YMD(:,2) == 2) & (T{k}.YMD(:,3) == 29);
T{k}(Lv,:) = [];
if nnz(Lv) % Optional 'if' Block
fprintf('Feb 29 removed from %s\n', fn{k})
end
end
end
Feb 29 removed from temp_summary.05.02_1981.txt
Feb 29 removed from temp_summary.05.02_1982.txt
T{:}
ans = 28x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 57 12 34.5 1981 2 1
2 58 19 38.5 1981 2 2
3 59 17 37 1981 2 3
4 59 12 35.5 1981 2 4
5 50 12 31.5 1981 2 5
6 54 31 42.5 1981 2 6
7 60 13 36.5 1981 2 7
8 51 29 40 1981 2 8
9 52 36 44 1981 2 9
10 59 24 41.5 1981 2 10
11 61 36 48.5 1981 2 11
12 67 28 46.5 1981 2 12
13 63 21 42 1981 2 13
14 63 29 46 1981 2 14
15 70 26 47 1981 2 15
16 72 29 51.5 1981 2 16
ans = 28x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 51 32 42.5 1982 2 1
2 52 24 39 1982 2 2
3 59 23 40 1982 2 3
4 45 27 37 1982 2 4
5 41 16 28.5 1982 2 5
6 48 10 28 1982 2 6
7 48 8 27 1982 2 7
8 52 20 36 1982 2 8
9 50 19 33.5 1982 2 9
10 35 30 33.5 1982 2 10
11 54 31 42.5 1982 2 11
12 56 27 40.5 1982 2 12
13 60 27 43.5 1982 2 13
14 63 35 48 1982 2 14
15 66 31 47.5 1982 2 15
16 70 40 56 1982 2 16
ans = 29x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 40 27 35.6 2016 2 1
2 40 20 29.1 2016 2 2
3 44 18 29.9 2016 2 3
4 50 22 35.6 2016 2 4
5 55 22 37.8 2016 2 5
6 59 22 39.5 2016 2 6
7 64 23 44.4 2016 2 7
8 69 34 49.8 2016 2 8
9 72 29 50 2016 2 9
10 72 25 46.8 2016 2 10
11 73 24 46 2016 2 11
12 69 22 44.4 2016 2 12
13 73 24 46.1 2016 2 13
14 68 26 47.3 2016 2 14
15 72 30 52.2 2016 2 15
16 75 29 50.4 2016 2 16
ans = 31x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 60 30 46 1981 3 1
2 59 27 42 1981 3 2
3 59 21 39 1981 3 3
4 56 38 47 1981 3 4
5 59 23 42 1981 3 5
6 64 21 42.5 1981 3 6
7 67 34 50.5 1981 3 7
8 69 28 47.5 1981 3 8
9 69 47 57 1981 3 9
10 64 51 58.5 1981 3 10
11 69 40 54.5 1981 3 11
12 70 30 51 1981 3 12
13 61 40 50.5 1981 3 13
14 57 43 49 1981 3 14
15 49 40 44.5 1981 3 15
16 45 36 39.5 1981 3 16
ans = 31x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 44 35 40.5 1982 3 1
2 61 31 46 1982 3 2
3 59 24 42 1982 3 3
4 50 43 45.5 1982 3 4
5 51 38 44.5 1982 3 5
6 55 38 46.5 1982 3 6
7 66 28 47 1982 3 7
8 66 32 48 1982 3 8
9 66 27 47.5 1982 3 9
10 62 30 47 1982 3 10
11 66 36 51 1982 3 11
12 55 35 45 1982 3 12
13 60 21 41.5 1982 3 13
14 66 27 46.5 1982 3 14
15 71 38 53 1982 3 15
16 63 40 51.5 1982 3 16
ans = 31x5 table
Day Maximum Temp Minimum Temp Average Temp YMD
___ ____________ ____________ ____________ ____________________
1 77 33 54 2016 3 1
2 76 32 52.6 2016 3 2
3 78 30 52.7 2016 3 3
4 71 35 51.5 2016 3 4
5 74 29 53 2016 3 5
6 68 41 57.8 2016 3 6
7 60 30 50.7 2016 3 7
8 47 27 37.2 2016 3 8
9 63 22 44.9 2016 3 9
10 67 29 49.7 2016 3 10
11 76 27 53.5 2016 3 11
12 72 38 56.6 2016 3 12
13 60 38 48.4 2016 3 13
14 61 28 48.1 2016 3 14
15 66 35 52.6 2016 3 15
16 71 25 48.3 2016 3 16
I just did this for the challenge! This should now produce the desired results.
.
その他の回答 (0 件)
参考
タグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)