필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How can I do this matix?

조회 수: 1 (최근 30일)
zeezo
zeezo 2018년 2월 26일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a matrix
a=[12 36 15 26 42 16 8 20]
I want to build a code that will read the matrix's elements and then see if the element < 40 it will take the element and divide by 2 if the element >40 it will stop and do not go through the rest elements
so in the example of a
It will takes the 12 and divide by 2 also 36, 15 and 26. When it reach 42 will divide it by 2 and stop there.
the element values might change
  댓글 수: 3
David Fletcher
David Fletcher 2018년 2월 26일
What happens if the element is equal to forty?
Walter Roberson
Walter Roberson 2018년 2월 26일
"What happens if the element is equal to forty?"
It leaves it unchanged and continues. Just like the implication that any element from the first that is greater than 40 to the end are not to be changed.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 26일
편집: Walter Roberson 2018년 2월 26일
Use for and if and break
There is also a vectorized way to do it using find() and logical indexing. (Actually, you can do it without find() if you get your logical indexing right.)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by