Problem in exporting function expression

3 ビュー (過去 30 日間)
duty duty
duty duty 2021 年 12 月 15 日
回答済み: Rahul 2025 年 1 月 24 日
Dear all
I get a function cd(x,y).I would like to export this function expression like this form:x^2+y^3... .What shall I do?
Part of a function expression:

回答 (1 件)

Rahul
Rahul 2025 年 1 月 24 日
I understand that you require to export your function expression comining x,y variables in the expression form as indicated in the question. In MATLAB, you can make use of 'syms' command to define Symbolic Scalar Variables and Functions. Here is an example:
syms x y
cd = -((x^2 + y^2)^(1/2)*(-(79819630675297226055697*x^2*y^2)/364791569817010176000 + (29968083657371368688627119*x^2*y^4)/))... % your expression
cd_str = char(cd);
% Exporting this expression in a text file
fileID = fopen('cd_expression.txt', 'w');
fprintf(fileID, '%s\n', cd_str);
fclose(fileID);
% This expression can be then converted from 'char' to function expression
% by using 'str2sym' function
exp = str2sym(cd_str);
Refer to the following MathWorks documentations to know more:
Hope this helps. Thanks!

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by