Basic question regarding adding A to all numbers greater than B

조회 수: 7 (최근 30일)
Angel
Angel 2018년 2월 1일
댓글: Angel 2018년 2월 1일
For example, if I have an array like x = (1:10); How would I add 2 to each number in that array that is greater than 5?

답변 (1개)

James Blackwell
James Blackwell 2018년 2월 1일
You could have an if function and go through the array element by element. If the number is greater than 5 you could add 2 to it :)
It sounds a bit like a homework question, so I don't think I'm supposed to give the code.
  댓글 수: 3
Steven Lord
Steven Lord 2018년 2월 1일
Since your homework assignment prohibits using if, its purpose is likely to familiarize you with logical indexing.
Angel
Angel 2018년 2월 1일
I'll look into that, thank you!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by