Replace a value if a condition is met

90 次查看(过去 30 天)
Hi, I got a little problem and I hoped someone can help me out.
When I have a matrix consisting of 3 columns, I want to replace a value in the third column if a row in the first column has a certain value. For example, I have the following matrix:
A =
3 6 9
2 6 8
3 6 8
Lets call the first column x, the second y and the third z. Now what I want is that when x == 3, than z must become 20.
How can I do this?

采纳的回答

Akira Agata
Akira Agata 2018-11-25
Please try the following:
idx = A(:,1) == 3;
A(idx,3) = 20;
  4 个评论
Danny Helwegen
Danny Helwegen 2018-11-25
This works, thank you very much and I will use the tip
Akira Agata
Akira Agata 2018-11-25
> Image Analyst
Thank you for your comment!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by