if statements with conditions at least number

1 回表示 (過去 30 日間)
danah alotaibi
danah alotaibi 2017 年 10 月 6 日
回答済み: Walter Roberson 2017 年 10 月 6 日
i have an homework to do a matlab code to sum all numbers between 0 and 999 with this excepts
  • Has at least one '7'
  • has both 2 and 5
  • divisible by 12
  • greater than 99 AND has a 0 in the middle
i try to do the code but how can i do these excepts
clc,clear all,close all
x=0:999;D=[x];
S=[];a=7;
for i=1:999
if any(D>a)
S(i)=D(i);
end
  1 件のコメント
James Tursa
James Tursa 2017 年 10 月 6 日
Can you explain your conditions in more detail. In particular, give several examples of specific numbers that match and do not match your criteria?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 10 月 6 日
[First, Second, Third] = ndgrid(0:9);
First = First(:); Second = Second(:); Third = Third(:);
First == 9 || Second == 9 || Third == 9 | ((First == 4 || Second == 4 || Third == 4) & (First == 3 || Second == 3 || Third == 3)) ....

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by