Filter löschen
Filter löschen

in algorithm a~b , in MATLAB...??????

2 Ansichten (letzte 30 Tage)
Meh
Meh am 19 Okt. 2011
Hi everybody, In an algorithm I am working on, I came to a check box with content:
a~b
where the '~' would be read as "a approximates b" which can be defined probably by absolute numerical difference. so if a~b=TRUE (i.e the difference b/n a and b is very small)further computations are done if not( i.e. a~b=FALSE) then termination! , if 'YES' it continues with other computations, and if 'NO' it terminates. How can I write this in MATLAB?
  1 Kommentar
Walter Roberson
Walter Roberson am 19 Okt. 2011
In that context, it would be read as "a approximates b". But like the others say below, you need to define what approximation means in the context.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Daniel Shub
Daniel Shub am 19 Okt. 2011
Assuming ~ mean not (or not equal) in your algorithm you could use ~= or ~isequal(). I prefer the isequal approach since it handles arrays and mismatched sizes ...
if isequal(a, b)
disp('NO')
else
disp('YES')
end
Although it seems a little backwards to me that a~b leads to YES.
  5 Kommentare
Jan
Jan am 28 Okt. 2011
@Meh: After you have clarified that "~" should mean "approximation", it got clear, that this amswer does not concern the question. Why do you accept it then as a solution?
It would be helpful for the forum, if you explain what "approximation" means qualitatively for your case. Then an answer would be very easy.
Daniel Shub
Daniel Shub am 28 Okt. 2011
It might also be helpful if I edited my answer to reflect the comment I made about comparing the difference to a tolerance. I am hesitant to do that since the answer has already been accepted.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by