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

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 28 de Mzo. de 2013

1 voto

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 comentarios

ropbasuel
ropbasuel el 28 de Mzo. de 2013
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
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Mzo. de 2013
Example
a=inputdlg('enter a');
a=str2double(a);
y=sin(a)
msgbox(['the result is' num2str(a)])
ropbasuel
ropbasuel el 28 de Mzo. de 2013
Editada: ropbasuel el 28 de Mzo. de 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
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Mzo. de 2013
it's
a=inputdlg ('enter a')
ropbasuel
ropbasuel el 28 de Mzo. de 2013
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
Azzi Abdelmalek
Azzi Abdelmalek el 28 de Mzo. de 2013
x=inputdlg({'enter a','enter b'})
a=x{1}
b=x{2}
ropbasuel
ropbasuel el 28 de Mzo. de 2013
Thank you Azzi! I really appreciate your help!
Thanks for your time!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by