Filter löschen
Filter löschen

Comparing terms in a character array

2 Ansichten (letzte 30 Tage)
vedesh Mohit
vedesh Mohit am 10 Feb. 2020
Kommentiert: vedesh Mohit am 10 Feb. 2020
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
" I would to add the term ('A*C') from the if statement into solve"
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.
  2 Kommentare
KSSV am 10 Feb. 2020
What is solve? Is it a string?
vedesh Mohit
vedesh Mohit am 10 Feb. 2020
Solve the character array

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

J. Alex Lee
J. Alex Lee am 10 Feb. 2020
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]
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

Weitere Antworten (0)


Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by