b=regexpre​p(b,'^','.​^','all'); doesn't works.

2 次查看(过去 30 天)
I want to replace ,/,^ to .,./,.^
my code:
syms t;
a='t^3+t*t+t^2/t';
b=a;
b=regexprep(b,'*','.*','all');
b=regexprep(b,'/','./','all');
b=regexprep(b,'^','.^','all');
Result I want:
a=t^3+t*t+t^2/t
b=t.^3+t.*t+t.^2./t
Real result:
a=t^3+t*t+t^2/t
b=t^3+t.*t+t^2./t
I think " b=regexprep(b,'^','.^','all');" doesn't works.
How can I fix this problem?

采纳的回答

Andrei Bobrov
Andrei Bobrov 2013-7-8
编辑:Andrei Bobrov 2013-7-8
syms t;
a=t^3+t*t+t^2/t;
b = vectorize(a);

更多回答(2 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-7-8
b=regexprep(b,'\^','.\^')

Jan
Jan 2013-7-8
STRREP is faster than REGEXPREP:
b = strrep(b, '^', '.^');

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by