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 ]
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!