How to limit a vector to a certain maximum
显示 更早的评论
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 个评论
Bill Tubbs
2021-5-6
回答(1 个)
Image Analyst
2012-11-29
xMax = 20;
x = [20 19 23 24 17]
% Clip to xMax
x(x>xMax) = xMax
5 个评论
Phil
2012-11-29
Walter Roberson
2012-11-29
newvector = min(x, 20);
Reno Marino
2020-2-13
u da man
James Pieris
2020-9-5
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
2020-9-6
Do a search in the help for "logical indexing".
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!