Error finding matrix indices where elements obey a condition
Show older comments
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 Comments
madhan ravi
on 22 Mar 2019
please attach your 30 by 1 matrix as a .mat file
ferda sonmez
on 22 Mar 2019
Luna
on 22 Mar 2019
Ferda, what is the source of your saved .mat file? Did you saved it yourself from your workspace?
ferda sonmez
on 22 Mar 2019
Luna
on 22 Mar 2019
As far as I understand your data already symbolic in your workspace. You should convert it into double array see my answer below.
You can also convert it before saving, when you load you will get the double array instead of symbolic array.
A = double(input_of_hidden_layer2)
save('SavedMatrix1.mat','A')
load('SavedMatrix1.mat') % you will see A 30x1 double in your workspace.
madhan ravi
on 22 Mar 2019
When you use vpa() or vpasolve() the class of the variable becomes symbolic.
Luna
on 25 Mar 2019
Ah now I understand, thx :)
Accepted Answer
More Answers (1)
Walter Roberson
on 23 Mar 2019
B = isAlways(A>0);
will give you a logical result. Or you could
B = logical(A>0);
1 Comment
Luna
on 25 Mar 2019
+1 :)
Categories
Find more on Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!