フィルターのクリア

Using for loop to evaluate polynomial for different values

1 回表示 (過去 30 日間)
Neha W
Neha W 2016 年 9 月 24 日
コメント済み: Image Analyst 2016 年 9 月 25 日
% Here N = 10 ; poly =[5 8 0]
for i = 1:N-1;
A = sum(poly);
B = mod(A,N);
end
i = i + 1;
But the end result shows the value for i = 1 (i.e. A=13, B = 3) only. I need to display A & B for i = 1 to 9

採用された回答

Image Analyst
Image Analyst 2016 年 9 月 24 日
Try this:
N = 10 ;
poly =[5 8 0];
for k = 1:N-1;
A = sum(poly);
B = mod(A,N);
fprintf('At iteration %d, A = %d, and B = %d\n', k, A, B);
end
You'll see
At iteration 1, A = 13, and B = 3
At iteration 2, A = 13, and B = 3
At iteration 3, A = 13, and B = 3
At iteration 4, A = 13, and B = 3
At iteration 5, A = 13, and B = 3
At iteration 6, A = 13, and B = 3
At iteration 7, A = 13, and B = 3
At iteration 8, A = 13, and B = 3
At iteration 9, A = 13, and B = 3
It displays A and B at every one of the 9 iterations, and you can see that they're all the same since A and B never are assigned anything that depends on the iteration number at all.
  2 件のコメント
Neha W
Neha W 2016 年 9 月 25 日
Sir, since i = 1: 10
if want A = [0 13 36...477] (% evaluate poly for every iteration till N-1) and the store the mod values in B = [0 3...7] array, What could be the procedure?
Image Analyst
Image Analyst 2016 年 9 月 25 日
You need to index A and B, like A(k) and B(k). Of course since you defined poly as a constant, A and B still won't change.

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

その他の回答 (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