How to replace values in a matrix?

6 次查看(过去 30 天)
Hello,
I am fairly new to MATLAB and I have a question. How do you replace a value in a matrix? So if I have a matrix A, where A=3,2,5,-6. How can I find, and replace all of the negative numbers with 0? So I want to end up with a matrix of 3,2,5,0.
Thank you!
Molly

采纳的回答

Star Strider
Star Strider 2015-9-21
One way is to use ‘logical indexing’:
A = [3,2,5,-6];
A(A<0) = 0
A =
3 2 5 0

更多回答(1 个)

Molly Baltins
Molly Baltins 2015-9-21
Thank you! This has helped a lot!
  5 个评论
Molly Baltins
Molly Baltins 2015-9-22
Perfect! That is exactly what u wanted! Thank you!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Analytics Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by