How to return value to zero before index of specific element in matrix?

조회 수: 3 (최근 30일)
Safia
Safia 2022년 9월 12일
댓글: Safia 2022년 9월 12일
Hi all!
I have a matrix (m*n), in each row i have a specific element that i want all element before it to be set to zero.
I extracted the index of specific element in column vector "V" . all i need now is to return values before this index "0".
thanks

채택된 답변

Matt J
Matt J 2022년 9월 12일
편집: Matt J 2022년 9월 12일
m=4;n=8;
Matrix=rand(m,n),
Matrix = 4×8
0.1866 0.9389 0.4492 0.7203 0.0563 0.4231 0.2116 0.7976 0.8085 0.5572 0.6158 0.9831 0.7248 0.2271 0.2121 0.2003 0.1690 0.7889 0.3033 0.0181 0.7499 0.4327 0.9734 0.0099 0.5639 0.1376 0.0910 0.0868 0.3564 0.9456 0.1187 0.6761
V=[3;7;2;5];
Matrix=Matrix.*((1:n)>=V),
Matrix = 4×8
0 0 0.4492 0.7203 0.0563 0.4231 0.2116 0.7976 0 0 0 0 0 0 0.2121 0.2003 0 0.7889 0.3033 0.0181 0.7499 0.4327 0.9734 0.0099 0 0 0 0 0.3564 0.9456 0.1187 0.6761

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by