Convert a symbolic expresion to a vector

convert a symbolic expression to a vector with length of the number of terms of the expression
235 Downloads
Updated 13 Sep 2013

View License

Convert each expression to a vector with length of the number of terms of an expression:
for example:
syms x a b c
r= a*x^2+b*x+c-exp(x)
R=sym2vec(r);
results in:
R =
[ c, -exp(x), b*x, a*x^2]

Limitations:
this is a rude way to solve the issue, the expression r always is expanded before assign to the vector
for example:
r = x*(a+b)+x
R=sym2vec(r)
you should have:
R=
[ x*(a+b), x]
but instead, you have:
R =
[ x, a*x, b*x]

Cite As

Luis Erasmo Miranda (2024). Convert a symbolic expresion to a vector (https://www.mathworks.com/matlabcentral/fileexchange/43479-convert-a-symbolic-expresion-to-a-vector), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Symbolic Math Toolbox in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0