How to generate -1, 0 and 1?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Sagar Dutta
am 19 Sep. 2019
Beantwortet: Steven Lord
am 19 Sep. 2019
I have these final values (A) which i want to convert into three distinct values "-1", "0" and "1". Is there any logic/function with which i can create these three values.
A= [ 0.6286 0.8418 0.0710 1.0000 0.0679 1.0000 -1.0000 0.9993
0.2775 -0.6166 0.1573 -0.9252 0.0696 1.0000 0.3095 -0.9932
-0.4295 0.1549 0.0091 -0.3527 -0.2070 -0.2481 0.7447 0.9579
0.8001 -0.5858 0.1576 -0.7784 0.2252 0.6288 -0.1014 -0.5635
-0.2302 0.9978 0.0942 -0.0956 0.2023 0.2124 0.1767 -0.4639
0.5237 -0.9969 -0.7340 -0.2531 0.5827 0.2777 -0.3598 0.4714
-0.3218 1.0000 -0.5890 -0.4673 0.4031 -0.1164 -0.1738 0.6229
-0.1244 -0.9800 -0.8206 -0.2040 -0.7268 -0.6902 0.0545 -0.3947]
Range of matrix A is from -1 to +1
0 Kommentare
Akzeptierte Antwort
Star Strider
am 19 Sep. 2019
Bearbeitet: Star Strider
am 19 Sep. 2019
I am not certain what result you want.
A = [ -0.6286 -0.8418 0.0710 1.0000 0.2679 1.0000 -1.0000 0.9999];
B = sign(A)
producing:
B =
-1 -1 1 1 1 1 -1 1
EDIT —
With your edited Question, my Answer remains the same, although the result obviously changes with your new ‘A’. (The new ‘B’ matrix becomes an appropriately-sized matrix of -1, 0, and 1, although there are no 0 values because there are no 0 values in the ‘A’ matrix.) Note that sign(0) will be 0, so that will work with an ‘A’ array with some elements being 0.
0 Kommentare
Weitere Antworten (1)
Steven Lord
am 19 Sep. 2019
If you want to map ranges of values in your original data to the values -1, 0, and 1 you could discretize your data. Use the syntax that accepts X, EDGES, and VALUES.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!