for loop not working

1 回表示 (過去 30 日間)
Apoorva Maiya
Apoorva Maiya 2019 年 7 月 24 日
コメント済み: Apoorva Maiya 2019 年 7 月 25 日
here is the for loop that im trying to run. my problem is the variable PON is not getting updated and assigned inside the for loop. Can someone please help?
% the size of VAL is 3*1. M=3. the issue is the value of PON is showing 0.
[M,N]=size(VAL);
PON=0;
for i=1:M
if(i>i+1)
PON=VAL(i+1); % when i execute this line seperately it works fine but when the whole code is executed the value of PON is not updated.
end
disp(PON)
break
end
  2 件のコメント
Matt J
Matt J 2019 年 7 月 24 日
編集済み: Matt J 2019 年 7 月 24 日
In what way is PON supposed to "update"? is it supposed to sum the values of "VAL" over the course of the loop?
Dennis
Dennis 2019 年 7 月 24 日
What is the goal of your if statement? I doubt that (i>i+1) will ever be true.

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

採用された回答

Matt J
Matt J 2019 年 7 月 24 日
The condition i>i+1 can never be true, so no wonder the line
PON=VAL(i+1);
is not executing. If it did execute, however, it would just over-write PON every time. Your code doesn't make it clear in what manner PON is supposed to "update" as new values of VAL are reached.
  1 件のコメント
Apoorva Maiya
Apoorva Maiya 2019 年 7 月 25 日
thankyou for the help sir, the statement
if(i>i+1)
was never true as you said. Thank you for the help.

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

その他の回答 (0 件)

カテゴリ

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