Azzera filtri
Azzera filtri

How to generate -1, 0 and 1?

2 visualizzazioni (ultimi 30 giorni)
Sagar Dutta
Sagar Dutta il 19 Set 2019
Risposto: Steven Lord il 19 Set 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

Risposta accettata

Star Strider
Star Strider il 19 Set 2019
Modificato: Star Strider il 19 Set 2019
I am not certain what result you want.
One option is the sign function:
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.

Più risposte (1)

Steven Lord
Steven Lord il 19 Set 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.

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by