フィルターのクリア

The greatest common divisor

2 ビュー (過去 30 日間)
Kentman
Kentman 2014 年 10 月 13 日
コメント済み: Kentman 2014 年 10 月 17 日
Hello,
-I have this matlab code:
function [nsd]=NaivniNSD(a,b)
if a>b
a=a-b;
else
b=b-a;
end
end
nsd=a;
- when i write (a=40;b=50) i still have the answer nsd=10 in matlab. a logical analysis will be b=10 so that nsd=a=40 not 10. I don't know what is the thing that i couldn't undersntand. Thank you.

採用された回答

Guillaume
Guillaume 2014 年 10 月 13 日
If that is indeed the function you are using, I'm surprised you don't get an error. Your
nsd = a;
is outside the function body. Put it before the last end.
  3 件のコメント
Guillaume
Guillaume 2014 年 10 月 13 日
編集済み: Guillaume 2014 年 10 月 13 日
I don't really understand your comment. As I said, in the code you've posted the nsd=a; is outside the body of the function. The 2nd end ends the function.
If it's not outside, then the code you've posted is not the one you're using. And the question is then, what is the actual code you're using?
Kentman
Kentman 2014 年 10 月 17 日
The thing was in my understanding of while cycle and its behaviour to a and b,now everything is working well, even with 'end'is written like this. Thank you anyway.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by