Why the numerical values for function handle from matlabFunction should be written one by one?

Hi guys,
I am now using matlabFunction for change a symbolic expression into a funtion handle.
I find a question like this: if I write the numeric values one by one to replace the symbolic variables like this:
1.JPG
then the answer can be obtained as 3.
However, if I write
F2= f( aa )
then, in the command window, it shows like this:
3.JPG
Could anyone help me about this question?
Thanks so much!

댓글 수: 2

What exactly is the problem?
Three scalar input arguments are not the same as a three-element vector input argument.
Hi Stephen,
Thanks so much for your reply!
I mean, the arguments cannot be input into the function handle in a vertor manner, but they are input as scalars. The number of variables in the problem is big, then we have to write the scalars one by one like this :
F2 = f( aa(1) , aa(2) , aa(3) , aa(4) , aa(5) , aa(6) , aa(7) , aa(8) , aa(9) , aa(10) , aa(11) , aa(12) , aa(13) , aa(14) , aa(15) , aa(16) , aa(17) , aa(18) , aa(19) , aa(20) , aa(21) , aa(22) ) ;
Are there any methods to write them in a more compact way?
Cheers

댓글을 달려면 로그인하십시오.

 채택된 답변

madhan ravi
madhan ravi 2018년 12월 12일
편집: madhan ravi 2018년 12월 12일
Because your function requires three inputs but you fed in 1
f(aa(1),aa(2),aa(3))

댓글 수: 6

Hi madhan,
Thanks so much for your reply!
I mean, the arguments cannot be input into the function handle in a vertor manner, but they are input as scalars. The number of variables in the problem is big, then we have to write the scalars one by one like this :
F2 = f( aa(1) , aa(2) , aa(3) , aa(4) , aa(5) , aa(6) , aa(7) , aa(8) , aa(9) , aa(10) , aa(11) , aa(12) , aa(13) , aa(14) , aa(15) , aa(16) , aa(17) , aa(18) , aa(19) , aa(20) , aa(21) , aa(22) ) ;
Are there any methods to write them in a more compact way?
Cheers
Yes using vars is the way to go. Pass aa cell array as vars and within the cell array each vector of variable names will be bunched together into aa single argument .
Dear Madhan,
Many thanks Madhan for the fast and efficient reply!
I think it must be an answer! I will try later when connecting to the PC with matlab!
It is really an amazing charm working in that way!
Cheers
Anytime :) , if you got the answer to your question make sure to accept the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2018년 12월 12일

댓글:

2018년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by