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

2 ビュー (過去 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
  1 件のコメント
Safia
Safia 2022 年 9 月 12 日
@Matt J Hi! thank you for your answer ! it works well!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by