strings become numbers and get in to the matrix

조회 수: 1 (최근 30일)
yonatan friedman
yonatan friedman 2019년 12월 22일
답변: Star Strider 2019년 12월 22일
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