Change values in vectors
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Io7 am 21 Jan. 2023
Kommentiert: Vilém Frynta am 21 Jan. 2023
I have a vector like: V=[1,2,3,4,5,6] and I want to substitute any values above 3 with the previous value in the vector which is “2”. So I want to have V=[1,2,2,2,2,2]. How to do this? Thank you.
Sulaymon Eshkabilov am 21 Jan. 2023
Bearbeitet: Sulaymon Eshkabilov am 21 Jan. 2023
IDX = find(V>3);
%% ALT. Way:
If you want to apply it to this vector, it's not complicated. But if you wanted to apply it to a more complex vector where the numbers don't go in ascending order, it woudle be bit more complicated.
I almost did it for you, but then I realized this sounds like a homework.
Please try, then we may help you. Try using find and indexing.
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!