Filter löschen
Filter löschen

Former behaviour of ~NaNs (of interest to Matlab users from mid-90s)

1 Ansicht (letzte 30 Tage)
Richard Hindmarsh
Richard Hindmarsh am 29 Jun. 2012
Hallo
I am running (for the first time since I wrote it) a Matlab script from 1996. In it I have a line where
a = ~b;
where b contains some NaNs. This used to run, but now, with the advent of the logical type, it won't accept ~NaN;
>> ~NaN Error using ~ NaN's cannot be converted to logicals.
But what was the value of ~NaN in those days? was it 0 or 1?
Thanks

Antworten (1)

Jan
Jan am 29 Jun. 2012
Bearbeitet: Jan am 30 Jun. 2012
1996 sounds like Matlab 4.2c or 5.0. In these times logical 's have been double 's with an extra flag. This has been change in 6.5.
I assume, that ~NaN has been NaN, even as logical type. But in the documentation I find "TRUE is everything but 0". I will try this in the evening with Matlab 5.3.
[EDITED: after running a test in Matlab 5.3]:
a = ~NaN;
disp(a)
% >> 0
class(a)
% >> double
islogical(a)
% >> 1
Therefore I assume this is required for your program:
b(isnan(b)) = 1; % Anything but 0
a = ~b;

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by