Replace selected elements in a vector if meeting some criteria
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Assume A=rand(10,1) is a column vector. B is a vector of position assume B=[2 4 7]. I want to check if any of the 2,4,7th rows elements in A is <0.5. If yes, change those elements in A to zero. I want finally modified A.
Within a loop, I can assess each elements of B (i.e. 2,4,7 one after another) and check the condition and make changes in A - that's straightforward. Is there any smarter way?
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!