How to transform matlab output to a 'matlab code' form?

10 visualizaciones (últimos 30 días)
Weijia Yao
Weijia Yao el 13 de En. de 2019
Respondida: Walter Roberson el 13 de En. de 2019
I am using symbolic expressions and symbolic functions to do some complicated calculations, such as computing a Jacobian of a vector fuction. Then the output is something like this
[a,b]
[c,d]
where a,b,c,d are symbols. This output is a matrix with a,b,c,d as entries, and it is very intuitive. However, I want the output to become [a,b; c,d], something that I can direcly 'copy-paste' to my matlab code and interpret by matlab directly. Of course I can manually change the output matrix to the 'matlab code' form, but sometimes my output is very complicated and I do not want to do it manually every time.

Respuestas (2)

madhan ravi
madhan ravi el 13 de En. de 2019
Editada: madhan ravi el 13 de En. de 2019
help diary
doc diary
  1 comentario
Weijia Yao
Weijia Yao el 13 de En. de 2019
I think this command cannot save the output in the 'matlab code' style.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 13 de En. de 2019
Use matlabFunction() instead.
copy/paste of symbolic expressions is like eval() on those expressions, which is a problem because symbolic expressions are in a language which is not exactly the same as MATLAB.
matlabFunction() generates anonymous functions that can then be executed on inputs to produce numeric results.
I recommend using the 'vars' option of matlabFunction to be sure that your variables are in the same order.
If you have inputs that should be vectors, then you should definitely use the 'vars' option. Look carefully at the {} syntax:
'vars', {[x0 x1 x2], a, b}
would created three inputs, the first of which expects arrays with three columns in which the corresponding rows together forming [x0, x1, x2] entries. Using [x0;x1;x2] there instead would create an input in which arrays with 3 rows were expected with the columns giving the x0, x1, x2 entries.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by