Error finding matrix indices where elements obey a condition

1 次查看(过去 30 天)
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 个评论
madhan ravi
madhan ravi 2019-3-22
When you use vpa() or vpasolve() the class of the variable becomes symbolic.

请先登录,再进行评论。

采纳的回答

Luna
Luna 2019-3-22
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)

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by