Error finding matrix indices where elements obey a condition

1 visualización (últimos 30 días)
ferda sonmez
ferda sonmez el 22 de Mzo. de 2019
Comentada: Luna el 28 de Mzo. de 2019
Hi,
I have a (30,1) matrix A filled with both positive and negative double values with high precisions.
I do the B= A>0 expecting a resulting matrix filled with 0s and 1s based on the value of original matrix such as
[0,
0,
1,
1,
0,
....]
However, when I display I get a matrix like below
0.0 < -60.80089912054130723383673691361028456512560544254638307756720395046146077078219605027697980403900146484375
0.0 < -40.47441497086561319883182687840919573785507473004455923328153712191512791918057700968347489833831787109375
0.0 < 11.9150901590727927897158716535914255438713276913571208738565018227240077663964257226325571537017822265625
0.0 < 50.24337655630030618369864852262179095255359883940103235308691394245261818696235422976315021514892578125
0.0 < -12.788094842081277874683606597932106962408104528383932295293478643982698628178695798851549625396728515625
0.0 < -19.7994345791724984686511623375698392780606832842132285447736268595153585891921466100029647350311279296875
0.0 < 44.20960440529531749044620672799080999950637846265719961065220598196712220584458918892778456211090087890625
0.0 < -38.4752715808701180299125340913012275096601820744906678455217984013980725421788520179688930511474609375
0.0 < -57.1261686699021779161260124218737353314343618323505877827184033790341999292650143615901470184326171875
0.0 < -15.50675798085333259859508957067109961395543474125240585269404109021451620975540208746679127216339111328125 0
Later when use matrix B in a matrix multiplication I get a lot of NaN values. Where am I doing wrong? I will be very appreciated if I can find a solution dfor this . Cause I am struggling due to this issue for a few days..
Best Regards,
Ferda
  7 comentarios
madhan ravi
madhan ravi el 22 de Mzo. de 2019
When you use vpa() or vpasolve() the class of the variable becomes symbolic.
Luna
Luna el 25 de Mzo. de 2019
Ah now I understand, thx :)

Iniciar sesión para comentar.

Respuesta aceptada

Luna
Luna el 22 de Mzo. de 2019
Hi Ferda,
Please see my comments below:
% first convert it to double array:
A = double(input_of_hidden_layer2);
% indexing your conditions:
B = A > 0;
% get the values which are greater than zero from that index:
A(B)

Más respuestas (1)

Walter Roberson
Walter Roberson el 23 de Mzo. de 2019
B = isAlways(A>0);
will give you a logical result. Or you could
B = logical(A>0);

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by