How to create new matrix in for loop?

1 Ansicht (letzte 30 Tage)
de Bord Julien
de Bord Julien am 28 Apr. 2022
Beantwortet: dpb am 28 Apr. 2022
I am trying to filter data greater than 0.02 in an existing matrix and create a new matrix with those values. Can someone tell me how to do this?

Akzeptierte Antwort

dpb
dpb am 28 Apr. 2022
MATLAB is "MATrix LABoratory" -- it operates on matrices and arrays by builtin syntax; that's a primary source of its power and usefulness. "We don't need no steenkin' loops!" :)
YIELDTHRESHOLD=0.02; % don't bury magic numbers in code; use variables so can change
DivYieldAboveThresh=DividendYield2019(DividendYield2019>YIELDTHRESHOLD); % use logical addressing
The above is one of the most powerful addressing features in MATLAB -- look up "logical addressing" in the documentation.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by