Converting double and integer value to logical array
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matuno
el 7 de Dic. de 2013
Comentada: Walter Roberson
el 9 de Dic. de 2013
I have looked for a clue on converting to logical array but could not find. My code:
function w = funcmake(n,k)
sc = func1(k);%func1 calls one function
l = [];
j0 = 0;
i0 = 0;
for s0 = 1:n
[r, i0, j0, sc]=func2(i0, j0, sc);%func2 calls another function
l = [l r];
w = xor(n, l);%Here I need to convert them into logical array otherwise showing 0
end
I need to convert n and l to logical array first otherwise result shows 0. I have tried with
y = logical(x) but it does not work.
Respuesta aceptada
Walter Roberson
el 9 de Dic. de 2013
In your line
w = xor(n, l)
your "n" is positive number that is at least 1, or else the "for s0 = 1:n" would not have executed any cycles at all.
Any non-zero number is considered to be logically true. xor() of true and something else is going to the logical NOT of the second value -- so it is going to be 0 if the second value is non-zero, and is going to be 1 only if the second value is 0.
I have no idea what you are hoping for.
Perhaps what you are hoping for is
binary_n = dec2bin(n) - '0';
2 comentarios
Más respuestas (1)
chitresh
el 7 de Dic. de 2013
y = im2bw(x)
try this it convert it to logical class
if problem is solved accept the answer
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!