strings become numbers and get in to the matrix

1 次查看(过去 30 天)
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 ]

回答(1 个)

Star Strider
Star Strider 2019-12-22
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.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by