Info

此问题已关闭。 请重新打开它进行编辑或回答。

mistake how can i stop

3 次查看(过去 30 天)
Heather Erickson
Heather Erickson 2019-4-2
关闭: MATLAB Answer Bot 2021-8-20
mistake loop needed, sorry
  1 个评论
per isakson
per isakson 2019-4-2
编辑:per isakson 2019-4-2
Homework?
mod(x,2) = 1
I think you mean
mod(x,2) == 1
See eq, ==

回答(1 个)

Jim Riggs
Jim Riggs 2019-4-2
编辑:Jim Riggs 2019-4-2
You probably want a loop from X=100:200
Inside your loop, you select the cases you want: e.g.
for x=100:200
condition1 = mod(x,2)==1 ; % odd number
condition2 = mod(x,11)==0; % multiple of 11
condition3 = mod(x,13)==0; % multiple of 13
if condition1 && (condition2 || condition3)
% this is the one you want
end
end
  1 个评论
Jim Riggs
Jim Riggs 2019-4-2
use a counter to keep track of the values that you want:
count=0;
for x=100:200
condition1 = mod(x,2)==1; % odd number
condition2 = mod(x,11)==0; % multiple of 11
condition3 = mod(x,13)==0; % multiple of 13
if condition1 && (condition2 || condition3)
count=coumt+1;
A(count)=x;
end
end
At the end of this loop, "count" is the number of values stored in A.

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by