'inline' command at 'for' loop... can we?
이전 댓글 표시
can we put 'inline' command at 'for' loop
I want to save several inline function at an array... Available?
채택된 답변
추가 답변 (2개)
Masoud Ghanbari
2013년 4월 17일
0 개 추천
댓글 수: 12
Jan
2013년 4월 17일
Please do not post details of the question as an answer, but inster it in the question, where readers expect them.
What does "get the function from user" exactly mean? It is impossible to guess this reliably.
I think what he wants to do is the same as discussed here:
Still dont use inline, use eval to generate the function handle. See me updated first post.
Masoud Ghanbari
2013년 4월 18일
Friedrich
2013년 4월 18일
As long the user enters a valid matlab expression you are fine to eval it.
>> user_input = '@(x,y) x+y'
user_input =
@(x,y) x+y
>> my_fcn = eval(user_input)
my_fcn =
@(x,y)x+y
>> my_fcn(3,10)
ans =
13
>>
Masoud Ghanbari
2013년 4월 18일
Friedrich
2013년 4월 19일
input returns a character array wheras inputdialog gives back a cell.
This @(x,y)x+y should give any error. What error do you get?
Masoud Ghanbari
2013년 4월 19일
Iman Ansari
2013년 4월 19일
편집: Iman Ansari
2013년 4월 19일
Hi. Use this:
f{i} = eval(user_input{1});
Masoud Ghanbari
2013년 4월 19일
Friedrich
2013년 4월 19일
Dude ;) Post your intput and the error message. A simply does not work wont help.
Masoud Ghanbari
2013년 4월 20일
Friedrich
2013년 4월 22일
You need to zuse {} instead of () when you call eval. inputdlg gives back a cell. Also don't use i to index into it. This should work:
f{i} = eval(user_input{1})
카테고리
도움말 센터 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!