Compile a simple function

Hi everyone, I'm a very young user of Matlab and completely new to the programming world. I'm trying to do a simple matlab program that ables me to calculate a simple Mathematical equation ( Newton's Law F=m.a).
I've done this simple code:
function F = Newton(m, a)
F=m*a
end
So, if I in Matlab type:
x=Newton(2,2) I get the result correctly.
So I tried to compile this simple .m file with the help of deploytool. But when I finish to create the .exe file, when I click on it nothing happens.
And, if I go to that .exe file through DOS line command, I can see that the error I get is:
Error using newton (line2) Not enough input arguments. MATLAB:minrhs
So, I need your help. I'm very new to this so I'm sorry if it is a stupid question.
Thanks to all that will try to help me
Regards

 Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 28 Mar 2013
when you compile only the function, how are you going to call this function? I think you should create a script with, for example inputdlg to introduce your data and msgbox or gui to display your result

7 Comments

I see.. So the problem is that I need some kind of dialog for the program know things right?
Is there any example I can see how this system works?
Thank you for your answer
Example
a=inputdlg('enter a');
a=str2double(a);
y=sin(a)
msgbox(['the result is' num2str(a)])
ropbasuel
ropbasuel on 28 Mar 2013
Edited: ropbasuel on 28 Mar 2013
Thank you for your example! Can you tell me what is wrong in this?
inputdlg ('enter a')
a=str2double(a);
inputdlg('enter m')
m=str2double(m);
F = m*a;
msgbox(['The result is' num2str(F)])
I get this error:
Undefined function or variable 'a'.
Error in newton (line 2) a=str2double(a);
Thanks
it's
a=inputdlg ('enter a')
Oh.. Now it works! Thank you for the help. Can I make only one more question?
Instead of having 2 steps in asking the variables, can I ask both variables at the same time? Like making a dialog with two different blank cases for me to put the values of "m" and "a" at the same time!
Thanks
x=inputdlg({'enter a','enter b'})
a=x{1}
b=x{2}
Thank you Azzi! I really appreciate your help!
Thanks for your time!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!