Making a table from data using rec
I am trying to use this code to create a table of when the data is in recession (when the value of q(x)>q(x-1)). However I do not know how to use the rec command.
T= readtable ("GDF.xlsx");
q=T(:,2);%The second column of the data is numerical, the first column is just dates
R=0;
for x=T
if q(x)>q(x-1) %Defining what a recession counts as
R=R+1;
rec(x)=1 %If it is a recession it =1, if not it will =0
else
rec(x)=0;
end
end
Error message that appears when I run this code:
Error using () (line 133)
Subscripting into a table using one subscript (as in t(i))
is not supported. Specify a row subscript and a variable
subscript, as in t(rows,vars). To select variables, use
t(:,i) or for one variable t.(i). To select rows, use
t(i,:).
Error in
Week4Q2 (line 8)
if q(x)>q(x-1)
Any idea on how to change the code so it produces a table of when the data is in recession? Help would be appreciated.I am trying to use this code to create a table of when the data is in recession (when the value of q(x)>q(x-1)). However I do not know how to use the rec command.
T= readtable ("GDF.xlsx");
q=T(:,2);%The second column of the data is numerical, the first column is just dates
R=0;
for x=T
if q(x)>q(x-1) %Defining what a recession counts as
R=R+1;
rec(x)=1 %If it is a recession it =1, if not it will =0
else
rec(x)=0;
end
end
Error message that appears when I run this code:
Error using () (line 133)
Subscripting into a table using one subscript (as in t(i))
is not supported. Specify a row subscript and a variable
subscript, as in t(rows,vars). To select variables, use
t(:,i) or for one variable t.(i). To select rows, use
t(i,:).
Error in
Week4Q2 (line 8)
if q(x)>q(x-1)
Any idea on how to change the code so it produces a table of when the data is in recession? Help would be appreciated. I am trying to use this code to create a table of when the data is in recession (when the value of q(x)>q(x-1)). However I do not know how to use the rec command.
T= readtable ("GDF.xlsx");
q=T(:,2);%The second column of the data is numerical, the first column is just dates
R=0;
for x=T
if q(x)>q(x-1) %Defining what a recession counts as
R=R+1;
rec(x)=1 %If it is a recession it =1, if not it will =0
else
rec(x)=0;
end
end
Error message that appears when I run this code:
Error using () (line 133)
Subscripting into a table using one subscript (as in t(i))
is not supported. Specify a row subscript and a variable
subscript, as in t(rows,vars). To select variables, use
t(:,i) or for one variable t.(i). To select rows, use
t(i,:).
Error in
Week4Q2 (line 8)
if q(x)>q(x-1)
Any idea on how to change the code so it produces a table of when the data is in recession? Help would be appreciated. table, rec, if statement, for loop, else MATLAB Answers — New Questions