フィルターのクリア

How are multiple for loops handled by matlab?

2 ビュー (過去 30 日間)
Benedikt Wessel
Benedikt Wessel 2018 年 9 月 24 日
編集済み: KALYAN ACHARJYA 2018 年 9 月 24 日
Hello, How's Matlab dealing with the following code? Is matlab checking the if condition like this: if 1=10 and then if 2=10 or if 2=50? My aim is that after the condition is true, every C(k) is added a C(n) till C(k)==C(n+1).
for k = 1:100
for n=[10,50,70]
if C(k)==C(n)
C(k:n+1)=C(k:n+1)+C(n)
end
end
end
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 24 日
What is c(k) here?

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

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 24 日
編集済み: KALYAN ACHARJYA 2018 年 9 月 24 日
assign k=1
n=10
if c(1)=c(10)
if yes then only c(1 to 11)=c(1 to 11)+c(10)
otherwise skip if condition
end
k=1, now n=50
if c(1)=c(50)
if yes then only c(1 to 51)=c(1 to 51)+c(50)
otherwise skip if condition
end
k=1n n=50
do the same
finished inner loop next
k=2 and rest are same n=10, n=50, ...
  2 件のコメント
Benedikt Wessel
Benedikt Wessel 2018 年 9 月 24 日
Thanks!
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 24 日
編集済み: KALYAN ACHARJYA 2018 年 9 月 24 日
Welcome!
Please note: for one k value inner loops for n=10, 50 and 70 completed then only k=2 and do the same

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

その他の回答 (1 件)

Dennis
Dennis 2018 年 9 月 24 日
This depends on how you nest your loops:
for k=1:100
for n=[10,50,70] %this is the inner loop it will be executed 100 times
end
end
for n=[10,50,70]
for k=1:100 %this is the inner loop it will be executed 3 times
end
end
Your example will check for
C(1)==C(10)
C(1)==C(50)
C(1)==C(70)
C(2)==C(10)
%...and so on
  2 件のコメント
Benedikt Wessel
Benedikt Wessel 2018 年 9 月 24 日
Thanks!
Benedikt Wessel
Benedikt Wessel 2018 年 9 月 24 日
Do you think the execution after the if function is correct? Because nothing happens, not even an error....

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

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by