필터 지우기
필터 지우기

Info

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

Modify this simple code for me, please

조회 수: 2 (최근 30일)
kenifeh
kenifeh 2011년 4월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
Recently, i asked a question about how to a certain number in the array of h to be displayed in the exact sequence. Someone gave me the correct answer. Please find the code below.
h=[2 4 6 1 7 5 9 8 9 2 5 7 2 4 6 7];
for p=1:16
index=input('please enter a number between 1 to 16:');
answer=h(index)
end
Can someone please help me modify this code? Now, i dont want it to request that i input any value of p before displaying the right value of h. I want it to be able to call the following
1. h(2)-h(1), h(3)-h(2), h(4)-h(3), h(5)-(h4), h(6)-h(5)...h(16)-h(15). 2. For the values in 1 above, display the figure(how many?) of digits that are less than 2
I need the answer to develop a specific code...Thanks, in anticipation of an urgent response
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 4월 10일
Is -5 less than 2 ?

답변 (1개)

the cyclist
the cyclist 2011년 4월 10일
dh = diff(h)
dh_less_than_2 = sum(dh<2)

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by