How to replace string but not function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ravi Goyal
am 18 Okt. 2016
Kommentiert: Ravi Goyal
am 21 Okt. 2016
Dear Community,
In a string like: 'sinh(x).*f.*n'
I want to replace the n with X_Model(1). Using strrep however I end up with
siX_Model(1)h.*f.*X_Model(1)
which means that the n in sinh was also found to be an n and replaced. How can I make it exclusiv, so only if it matches exactly the replacement does take place? In a Matlab Script using 'Find and Replace' I can make this happen when I click 'Match Case' and 'Whole Word', so I want to have this functionality in a function.
Thanks and best Regards Ravi
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 18 Okt. 2016
Bearbeitet: Sean de Wolski
am 18 Okt. 2016
This can be done elegantly and safely with Symbolic Math Toolbox
syms x f n model(ix)
expr = sinh(x).*f.*n
subs(expr,n,model(1))
2 Kommentare
Siehe auch
Kategorien
Mehr zu Software Development Tools 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!