Make a vector based on for loop values

조회 수: 1 (최근 30일)
Hannah Wood
Hannah Wood 2020년 10월 7일
댓글: madhan ravi 2020년 10월 7일
I need to make a code to find the number of values between 120 and 230 that are odd and are multiples of 11 and 13, then store the answers in a vector. I can't quite figure out how to make a vector based on the for loop. All I can manage to get is
n = [120:+1:230];
for n = 120:230;
if mod(2,2) == 1;
else mod(n,11) == 0 && mod(n,13) == 0;
end
end
  댓글 수: 2
Stephen23
Stephen23 2020년 10월 7일
Is it a requirement to use a loop? The MATLAB approach would be to use logical indexing without any loop.
Hannah Wood
Hannah Wood 2020년 10월 7일
My teacher is requiring that we use a loop

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

채택된 답변

madhan ravi
madhan ravi 2020년 10월 7일
You are close:
if (mod(n,2) == 1)&& (mod(n,11) == 0 || mod(n,13) == 0);
If the above statement is true , you will save n in a variable.
  댓글 수: 2
Hannah Wood
Hannah Wood 2020년 10월 7일
Thank you. I think my issue is still in how to save n in a variable
madhan ravi
madhan ravi 2020년 10월 7일
doc for % I would suggest you to do MATLAB On-ramp course

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by