'inline' command at 'for' loop... can we?
Show older comments
can we put 'inline' command at 'for' loop
I want to save several inline function at an array... Available?
Accepted Answer
More Answers (2)
Masoud Ghanbari
on 17 Apr 2013
0 votes
12 Comments
Jan
on 17 Apr 2013
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
on 18 Apr 2013
Friedrich
on 18 Apr 2013
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
on 18 Apr 2013
Friedrich
on 19 Apr 2013
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
on 19 Apr 2013
Iman Ansari
on 19 Apr 2013
Edited: Iman Ansari
on 19 Apr 2013
Hi. Use this:
f{i} = eval(user_input{1});
Masoud Ghanbari
on 19 Apr 2013
Friedrich
on 19 Apr 2013
Dude ;) Post your intput and the error message. A simply does not work wont help.
Masoud Ghanbari
on 20 Apr 2013
Friedrich
on 22 Apr 2013
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})
Masoud Ghanbari
on 20 Apr 2013
0 votes
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!