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

4 次查看(过去 30 天)
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