From: Stacy Ross on
Hello Everyone:

I am trying to convert a logical true statement into a double 1 value. And likewise for false.

Right now I have an m x n of values called original. I used new=original>setvalue. Then I wanted to multiply the original by the logic so anywhere below the setvalue will be 0, but anything above the set value will be the original value.

Thank you in advance!

original:
1 4 3
3 4 5

new (greater than 2)
0 1 1
1 1 1

Desire to multiply those two to get:
0 4 3
3 4 5


Stacy
From: Jan Simon on
Dear Stacy,

> I am trying to convert a logical true statement into a double 1 value. And likewise for false.
>
> Right now I have an m x n of values called original. I used new=original>setvalue. Then I wanted to multiply the original by the logic so anywhere below the setvalue will be 0, but anything above the set value will be the original value.
>
> original:
> 1 4 3
> 3 4 5
>
> new (greater than 2)
> 0 1 1
> 1 1 1
>
> Desire to multiply those two to get:
> 0 4 3
> 3 4 5

TRUE to 1, FALSE to 0:
double(TRUE), double(FALSE)
Your matrix operation:
A = [1, 4, 3; 3, 4, 5];
A(A<=2) = 0;
or
M = (A > 2);
B = A .* M;
In the later you see, that the LOGCIAL matrix is converted to DOUBLE automatically.You can do this explicitely e.g. to support debugging:
B = A .* double(M);

Good luck, Jan
From: Steven_Lord on


"Stacy Ross" <stacy.sommerfeld(a)gmail.com> wrote in message
news:i1t0a0$32l$1(a)fred.mathworks.com...
> Hello Everyone:
>
> I am trying to convert a logical true statement into a double 1 value.
> And likewise for false.
> Right now I have an m x n of values called original. I used
> new=original>setvalue. Then I wanted to multiply the original by the
> logic so anywhere below the setvalue will be 0, but anything above the set
> value will be the original value.

There's no need to go to the work of computing the product. Just use
indexing instead.

> original:
> 1 4 3
> 3 4 5
>
> new (greater than 2)
> 0 1 1
> 1 1 1
>
> Desire to multiply those two to get:
> 0 4 3
> 3 4 5

A = [1 4 3; 3 4 5];
G = A > 2;
B = zeros(size(A));
B(G) = A(G)

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: us on
"Stacy Ross" <stacy.sommerfeld(a)gmail.com> wrote in message <i1t0a0$32l$1(a)fred.mathworks.com>...
> Hello Everyone:
>
> I am trying to convert a logical true statement into a double 1 value. And likewise for false.
>
> Right now I have an m x n of values called original. I used new=original>setvalue. Then I wanted to multiply the original by the logic so anywhere below the setvalue will be 0, but anything above the set value will be the original value.
>
> Thank you in advance!
>
> original:
> 1 4 3
> 3 4 5
>
> new (greater than 2)
> 0 1 1
> 1 1 1
>
> Desire to multiply those two to get:
> 0 4 3
> 3 4 5
>
>
> Stacy

one of the many solutions

m=[
1 4 3
3 4 5
];
r=m.*double(m>2)
%{
% r =
0 4 3
3 4 5
%}

us
From: James Tursa on
"us " <us(a)neurol.unizh.ch> wrote in message <i21sik$ldp$1(a)fred.mathworks.com>...
>
> one of the many solutions
>
> m=[
> 1 4 3
> 3 4 5
> ];
> r=m.*double(m>2)
> %{
> % r =
> 0 4 3
> 3 4 5
> %}

FYI, you don't need the double conversion explicitly since MATLAB does that automatically. e.g., the following will work:

r=m.*(m>2)

James Tursa