Subs with 2 numbers returns a number

2 visualizaciones (últimos 30 días)
fdadasd asdasd
fdadasd asdasd el 10 de Nov. de 2021
Respondida: John D'Errico el 11 de Nov. de 2021
Subs when given 2 numbers, returns a number. But I need a string/function to be returned
example:
>> syms x y;
>> f=-y+x+2;
>> subs(f, [x,y], [2,2])
ans =
2
>>
But I need it: -2+2+2

Respuestas (2)

Star Strider
Star Strider el 10 de Nov. de 2021
It is doing the substitution and the calculation at the same time, and providing the answer.
Using symbolic arguments instead —
syms x y a b
f=-y+x+2;
subs(f, [x,y], [a,b])
ans = 
as expected.
.

John D'Errico
John D'Errico el 11 de Nov. de 2021
Simple enough. Convert the original expression to a string. Now just do string processing, with finds and replace operations.
Can you do it using symbolic computations? Probably not, since subs will combine those numeric constants for you automatically.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by