How to create new matrix in for loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
dpb
2022년 4월 28일
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.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!