Filter löschen
Filter löschen

Create new variable using if function from existing array variables

2 Ansichten (letzte 30 Tage)
nskel
nskel am 30 Jul. 2019
Beantwortet: Alex Mcaulley am 30 Jul. 2019
Hi,
I have a table 'PMIdata' with 3 columns; 1st column is the date (monthly), 2nd column is a numeric value 'PMInum' corresponding to that date (economic growth) and 3rd column is a moving average of the second column 'PMIave' (so again numeric). I would like to add a fourth column 'AboveMA' to the table that specifies whether for each element in the 2nd column if it is greater than the corresponding element in the 3rd column, i.e. a binary variable of 0 or 1 indicating if the value is greater than its moving average (for all given dates).
I think this should be done using an 'IF' statement but I'm not sure of the syntax to navigate through the arrays and how to append this fourth column to the table.
Any help would be appreciated.
Thanks!

Antworten (1)

Alex Mcaulley
Alex Mcaulley am 30 Jul. 2019
Try this:
PMIdata.AboveMA = PMIdata.PMInum > PMIdata.PMIave;

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by