フィルターのクリア

How to use user input for fittype function

2 ビュー (過去 30 日間)
Josiah McCarther
Josiah McCarther 2016 年 3 月 16 日
編集済み: Javier Bastante 2016 年 3 月 25 日
I want to take user inputs for a function and in turn use it in the fittype function. I realize that the fittype uses only string values so I converted my input to a string. However it is still not working and it keeps giving me this:
Error using fittype Expected a string for the parameter name, instead the input type was 'cell'.
Here is my code:
g=input('input your function','s')
f = fittype('g',{g});
nargs = numargs(f)
args = argnames(f)
args=sym(args)
and this is my input that I'm using for g:
a*x^2+b*exp(n*x)
Thanks

採用された回答

Javier Bastante
Javier Bastante 2016 年 3 月 16 日
Try this:
ft = fittype( 'a*x^2+b*exp(n*x)', 'independent', 'x', 'dependent', 'y' )
  2 件のコメント
Josiah McCarther
Josiah McCarther 2016 年 3 月 24 日
Thanks for the response, but I don't think this is exactly what I'm looking for. I want to be able to read out the variables of a function based on user input instead of typing the equation directly into the code.
Javier Bastante
Javier Bastante 2016 年 3 月 25 日
編集済み: Javier Bastante 2016 年 3 月 25 日
well you are right, but then use this:
g=input('Input your function: ','s');
ft = fittype( g, 'independent', 'x', 'dependent', 'y' )
and then introduce your input function, a*x^2+b*exp(n*x), or whatever.
I use this way, what I saw on your code us that you introduced {g} as input argument, and that's why MATLAB says that you are introducing a cell because {} are used for cell variables. I hope it works this time. Regards

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by