How to limit a vector to a certain maximum
Ältere Kommentare anzeigen
I have the vector x = [20 19 23 24 17] and I want to somehow create a vector that contains nothing greater than 20. That is, I need a vector that returns y = [20 19 20 20 17] from the original vector. The methods I have tried only return some sort of a boolean type vector that tells me which values are greater than 20. Can anyone help me?
1 Kommentar
Bill Tubbs
am 6 Mai 2021
Antworten (1)
Image Analyst
am 29 Nov. 2012
xMax = 20;
x = [20 19 23 24 17]
% Clip to xMax
x(x>xMax) = xMax
5 Kommentare
Phil
am 29 Nov. 2012
Walter Roberson
am 29 Nov. 2012
newvector = min(x, 20);
Reno Marino
am 13 Feb. 2020
u da man
James Pieris
am 5 Sep. 2020
Hi, do you think you can reference the matlab feature x (x> xmax) from which you derived this technique? I am just interested to know where this defined/listed in matlab documentation. Thanks a lot. it works.
Image Analyst
am 6 Sep. 2020
Do a search in the help for "logical indexing".
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!