Discussion:
How to convert a logical to double
(too old to reply)
Parshuram M. Kamble
2017-08-26 09:25:09 UTC
Permalink
Hi all,
How does one convert a logical array back to an array of doubles without
a_logical = logical( [ 1 2 3 ] );
a_double = a_logical + 0;
Is seems to me that this is inefficient. Why should you need to add a value
(even if it is zero) to every element in a vector just to change from
a_double = double( a_logical )
would work, but it doesn't.
Jordan
Parshuram M. Kamble
2017-08-26 09:34:09 UTC
Permalink
Hi all,
How does one convert a logical array back to an array of doubles without
a_logical = logical( [ 1 2 3 ] );
a_double = a_logical + 0;
Is seems to me that this is inefficient. Why should you need to add a value
(even if it is zero) to every element in a vector just to change from
a_double = double( a_logical )
would work, but it doesn't.
Jordan
Clear all;
close all;
I=imread('imageTest1.bmp');
[r,c]=size(I)
g=[];
g=double(I);
dpb
2017-12-16 14:51:21 UTC
Permalink
Hi all,
How does one convert a logical array back to an array of doubles without
   a_logical = logical( [ 1 2 3 ] );
   a_double = a_logical + 0;
Is seems to me that this is inefficient.  Why should you need to add a
value
(even if it is zero) to every element in a vector just to change from
   a_double = double( a_logical )
would work, but it doesn't.
Jordan
Of course double(a_logical) works; it's just that a_double ~= [ 1 2 3 ]
if that is the intent. Once the operation logical( [ 1 2 3 ] ) has been
completed, there's no recovering the numeric values of 2, 3; what the
specific values were is gone entirely; only the result of whether the
values were/were not zero is retained.

The lesson to be learned is that if one is going to need the numeric
values of the initial vector again, don't destroy them.

--

Loading...