matrix if statement is above .5 then can I re enter it to show .5

3 次查看(过去 30 天)
I have a large matrix(x) and I want to change any value the is above .5 or below -.5 to .5 or -.5 respectively in a certain column(2). any assistance regarding this topic would be greatly appreciated.
regards, cormac

采纳的回答

Guillaume
Guillaume 2015-4-27
I'm sure it's covered in the Getting Started tutorials. It's basic matrix indexing.
A = rand(10, 10)*2-1; %create matrix between -1 to 1, for demo
A(A < -0.5) = -0.5;
A(A > 0.5) = 0.5

更多回答(1 个)

Thorsten
Thorsten 2015-4-27
R = randn(10)/3;
R(R > 0.5) = 0.5;
R(R < -0.5) = -0.5;

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by