I have a column of data with rainfall on each day, from 2004 to 2016. I want to be able to extract the rainfall data for each day and store that data into columns of months for each year. I have created a loop that finds the end day of all months from 2004 to 2016, but am having trouble now extracting the information.
[SL: formatted question as text not code]

댓글 수: 2

Mohammad Sami
Mohammad Sami 2020년 3월 24일
편집: Mohammad Sami 2020년 3월 24일
Create a vector to store the index of the days (rows) you want to extract. Then you can simply subset.
Asanka Subasinghe
Asanka Subasinghe 2020년 3월 24일
I need some sort of loop because theres more than 4000 data points

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 3월 24일
편집: Walter Roberson 2020년 3월 24일

0 개 추천

Dv = Dates(:) ;
Output = accumarray([day(Dv), month(Dv), year(Dv)-2003], Rainfall(:), [31 12 13], [], nan);
The result will be a 3d array with one pane for each year, with rows being day numbers, columns being month numbers. Unused entries such as shorter months or missing data will be set to nan

댓글 수: 6

Asanka Subasinghe
Asanka Subasinghe 2020년 3월 25일
I am receiving an error message that says
Error using accumarray
First input SUBS and third input SZ must satisfy
ALL(MAX(SUBS)<=SZ).
Can you please explain what each input of accumarray does?
Thanks
current code is :
clc;clear all;close all
filename='Data Q2 (2).xlsx';
[num,txt,raw]=xlsread(filename);
dandenongdate=txt(2:end,1);
dandenongnum=num(:,1);
Dv = dandenongdate ;
Output = accumarray([day(Dv), month(Dv), year(Dv)-2003], dandenongnum, [31 12 13], [], nan);
Walter Roberson
Walter Roberson 2020년 3월 25일
Use readtable so that you get datetime objects not date vectors.
Asanka Subasinghe
Asanka Subasinghe 2020년 3월 25일
It tells me Error using day (line 37)
You cannot subscript a table using linear indexing (one
subscript) or multidimensional indexing (three or more
subscripts). Use a row subscript and a variable subscript.
What does it mean by row and variable subscript?
Thank you
clc;clear all;close all
filename='Data Q2 (2).xlsx';
data=(readtable(filename))
dandenongnum=data(:,2);
dandenongdate=data(:,1);
Dv=dandenongdate;
Output = accumarray([day(Dv), month(Dv), year(Dv)-2003], dandenongnum, [31 12 13], [], nan);
clc;clear all;close all
filename='Data Q2 (2).xlsx';
data=(readtable(filename))
dandenongnum=data{:,2};
dandenongdate=data{:,1};
Dv=dandenongdate;
Output = accumarray([day(Dv), month(Dv), year(Dv)-2003], dandenongnum, [31 12 13], [], nan);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 3월 24일

댓글:

2020년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by