Why does the sum of S1 AND S2 ?

1 回表示 (過去 30 日間)
Tomas
Tomas 2013 年 11 月 8 日
コメント済み: Walter Roberson 2013 年 11 月 9 日
S1=[23.6000 58.4000 47.4000 101.7000 29.9000 36.8000] S2=[23.6000 58.4000 47.4000 67.1000 29.9000 71.4000]
c=0; while (S1~=S2)
c=S1+S2
end
c
Why does the sum of S1 AND S2 ?
Thanks.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 8 日
編集済み: Azzi Abdelmalek 2013 年 11 月 8 日
Maybe you want
S1=[23.6000 58.4000 47.4000 101.7000 29.9000 36.8000]
S2=[23.6000 58.4000 47.4000 67.1000 29.9000 71.4000]
c=0;
while ~isequal(S1,S2)
c=S1+S2
end
  2 件のコメント
John D'Errico
John D'Errico 2013 年 11 月 8 日
I think you misunderstand how while works. It cannot loop over the elements of S1 as you have written it.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 8 日
I don't know what you want. Can you explain?

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


Walter Roberson
Walter Roberson 2013 年 11 月 8 日
Your while loop does not change S1 or S2, so the body will either not be done at all (if the condition does not hold at the beginning) or will be done repeatedly without end.
  4 件のコメント
Tomas
Tomas 2013 年 11 月 8 日
編集済み: Tomas 2013 年 11 月 8 日
i don't understand english very well :)
Walter Roberson
Walter Roberson 2013 年 11 月 9 日
A = 0.3 - 0.2 - 0.1;
B = 0;
if A == B
disp('the two are equal')
else
disp('the two are not equal')
end
if abs(A-B) < eps(0.3)
disp('the two are approximately equal')
else
disp('the two are not approximately equal')
end
Do not compare floating point numbers for equality.
Also, you are comparing two arrays. Read the documentation for "if"
An evaluated expression is true when the result is nonempty and contains all nonzero elements (logical or real numeric). Otherwise, the expression is false.

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

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by