data loop for matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
for i= 1977:2012
for j=1:12
for k=1:31
mx=min(q1,[],'omitnan');
end
end
end
댓글 수: 4
채택된 답변
Adam Danz
2020년 11월 18일
- Read data in as a table (see readtable)
- Convert the year-month-day columns to a single datetime vector and convert the table to a timetable
- Use retime to get the monthly max
Demo:
% Create demo table
T = table([1977;1977;1977;1977;1978;1978],[11;11;12;12;1;1],[1;2;1;2;1;2],(2:7)','VariableNames',{'Year','Month','Day','MaxTemp'})
% Convert to datetime values
TT = timetable(datetime(T.Year,T.Month,T.Day),T.MaxTemp,'VariableNames',{'MaxTemp'})
% Get monthly max
TT_MonthlyMax = retime(TT,'Monthly','max')
If any month is missing from the data, the MaxTemp for that month will be NaN. Those rows can be removed with,
TT_MonthlyMax(isnan(TT_MonthlyMax.MaxTemp),:) = [];
댓글 수: 20
Steven Lord
2020년 12월 8일
An empty cellstr is by {0x0 char} whereas a missing cellstr could be represented by {''} or perhaps {NaC} (Not-a-char, when the entire char array is 'missing') which would be consistent with cell arrays of doubles (NaN) or datetimes (NaT), etc.
Instead of trying to find some way to represent missing data in a cellstr, I probably would store my text data (including missing) in a string array and use the string array instead of a cellstr.
A = ["apple"; "banana"; "cherry"; missing; "eggplant"]
Adam Danz
2020년 12월 8일
편집: Adam Danz
2020년 12월 8일
Thanks, Steven Lord, strings do solve that problem and they distinguish between empties and missing.
A = ["apple"; ""; "cherry"; missing; "eggplant"]
But the bigger picture I'd like to emphasize is the option to treat empties as missing in the fillmissing(), rmmissing() etc family of functions. The current workaround is to find the empty arrays and replace them with missing values and for most data types, the missing() function comes in handy to fill with <missing> but missing() does not support cell arrays. So I'm suggesting that the _missing() family of functions optionally treat empty arrays as missing and to do this for empty cells as well.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!