Comparing terms in a character array

조회 수: 2 (최근 30일)
vedesh Mohit
vedesh Mohit 2020년 2월 10일
댓글: vedesh Mohit 2020년 2월 10일
Hey,
I have character array with terms solve= (B*C) + (A*~C), I am comparing terms from table to determine if it exist exact in the character array. I tried.
if strcmp(solve,'A*C')
do nothing
else
" I would to add the term ('A*C') from the if statement into solve"
end
Can anyone assist me in matching if the exact term exist in the array & if not I would to add it to the existing character array.
Thanks.
  댓글 수: 2
KSSV
KSSV 2020년 2월 10일
What is solve? Is it a string?
vedesh Mohit
vedesh Mohit 2020년 2월 10일
Solve the character array

댓글을 달려면 로그인하십시오.

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 2월 10일
If it is truly a "character array" and you want exact matches only, you can use the findstr() command, which will return empty if not found
expr = '(B*C) + (A*~C)'
newterm = '(A*C)'
if isempty(findstr(expr,newterm))
expr = [expr ' + ' newterm]
end
If your expression is a string as KSSV was asking, you can do
expr = "(B*C) + (A*~C)"
newterm = '(A*C)'
if ~expr.contains(newterm)
expr = expr + " + " + newterm
end
  댓글 수: 1
vedesh Mohit
vedesh Mohit 2020년 2월 10일
Thank you. The first part worked well

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by