strings become numbers and get in to the matrix

1 visualización (últimos 30 días)
yonatan friedman
yonatan friedman el 22 de Dic. de 2019
Respondida: Star Strider el 22 de Dic. de 2019
i have a matrice
[1 0 -1 -1 2 -1 1
1 0 -1 -1 2 -1 1
1 -1 0 -1 2 -1 1
1 0 -1 -1 2 -1 1];
and where the number is positive i need to replace ' i ' upon the ASCII is 105 , ( ' i ' its like increase )
where the number is negative i need to replace ' d ' upon the ASCII is 100 ( ' d ' its like decrease )
and where the number is 0 i need to replace ' s ' upon the ASCII is 115 ( ' s ' its like same )
------------------------------------------
for example : if i have vector [ -1 , 0 , 1]
the new vector will be : [100 , 115 , 105 ]

Respuestas (1)

Star Strider
Star Strider el 22 de Dic. de 2019
Use logical indexing:
v = [ -1 , 0 , 1];
pos = v > 0
neg = v < 0
zro = v == 0
and then do the replacements.
See the documentation section on Matrix Indexing for an extended discussion.

Community Treasure Hunt

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

Start Hunting!

Translated by