Replace specific numbers in a matrix

조회 수: 3 (최근 30일)
Fahad Mirza
Fahad Mirza 2014년 2월 2일
댓글: Fahad Mirza 2014년 2월 2일
I am in a noob level right now. So, question might look silly. But here is it anyway:
I have a matrix of 10x10 with integer numbers. I need to find the numbers which are greater then 90 and replace it with 'inf'. I can replace those numbers with zero by using conditional operator. Like: A = A.*(A<90)
But how can I replace them with 'inf'? I know I can use 'for' and 'if-else'. But there must be more elegant way to do that I guess.

채택된 답변

Amit
Amit 2014년 2월 2일
Lets say your matrix is called A, then
A(A>90) = Inf;
That simple :)
  댓글 수: 1
Fahad Mirza
Fahad Mirza 2014년 2월 2일
Wow!! That simple. I don't know why it didnt come to my mind. Thanks a lot :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by