How can I embed my .m file(function) in my GUI?

I am trying to make a GUI which can take functional inputs from the user and can plot various graphs and contours based on the input by the user. I'm not able to find some inbuilt command which I can use directly.

5 Comments

Just call it from the callback of whatever button or control you want to trigger it, in the same way you would call it from anywhere else.
The Matlab help gives examples of how to get inputs from UI controls and use them in a callback.
I know about this command, but what I'm looking for some command in 'Callback' option which accepts functional input. e.g.- "val = get(hObject,'Value');" this command accepts numeric value given by the user.
It's still not clear what you want the GUI to do, or how the question is related to what you want to do.
"How can I embed my .m file in my GUI?"
Your GUI will know how to access your .m file if the .m file is in the working directory or in the matlab path. When compiling your GUI for standalone application, matlab will determine where your .m files are and "embed" them into your application to work.
To help us understand better:
  • What do you mean by "functional input"? An input that is a function string or handle?
  • Is the user providing a numerical value, OR, a string command that must be evaluated as a function?
  • Is the user using an editable text box to input data or something else? With an editable text box, you do this :
Val = str2double(get(hObject, 'String')); %gets value in the edit text box
Thank you very much for your response. I would like to clear things on what I was trying to say.
  1. By saying "functional input", I want user to give any variable function e.g.- y=x^2+3 and it should plot y w.r.t. x. What I'm trying to do is to take 3 different inputs in x,y,z variables only, and at the and I want to plot these inputs wrt x,y, or z.
  2. Second thing I don't wnt a numerical input rather I want a variable input which I can plot.
  3. user will provide input in the 'Editable Text Box'.
Sounds like what you are expecting is a full-blown parser. I'm not aware that anything in base Matlab can handle equations written like that. Maybe the Symbolic Toolbox can.
doc fplot
can do some plotting of a function, but it needs a function handle as far as I understand, not an equation in a string.

Sign in to comment.

 Accepted Answer

Provided that you do not need to compile your code, there are two basic approaches:
  1. use str2func() to create an anonymous function. This is usually fine for numeric work.
  2. use the symbolic toolbox. In R2017b, use str2sym; in earlier versions use sym() (you might get a warning.)
  3. you might also be able to use inline(), but this is not recommended.

More Answers (1)

Categories

Asked:

on 8 Nov 2017

Answered:

on 8 Nov 2017

Community Treasure Hunt

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

Start Hunting!