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

4 vues (au cours des 30 derniers jours)
Safia
Safia le 12 Sep 2022
Commenté : Safia le 12 Sep 2022
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

Réponse acceptée

Matt J
Matt J le 12 Sep 2022
Modifié(e) : Matt J le 12 Sep 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by