How to make M-File with function and "header"

Hello, I am facing a little problem as i describe:
I need to make .m file with function that receives data compute it and give back the result, this is easy (I know how to make this). But in this M-file must be included names of parameters of this function and their default values that I can access from another M-file.
for example:
function [m,s] = func1(arg1,arg2,arg3)
%calculation here
[m,s];
end
and the "header" in same M-file should give:
  • arg1,arg2,arg3 as strings
  • and default values of arg1,...,arg3 as number
when other M-file ask for them
Is this possible and how to make it?

1 comentario

Jan
Jan el 7 de Mzo. de 2013
Editada: Jan el 7 de Mzo. de 2013
I cannot imagine in which situation this could be useful. What does "header" exactly mean and how does it "give"?
Please use meaningful tags.

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 7 de Mzo. de 2013
Editada: Jan el 7 de Mzo. de 2013
Perhaps you want:
function [m,s] = func1(arg1,arg2,arg3)
if nargin == 0
% Reply names of inputs and default values:
m = {'arg1','arg2','arg3'};
s = {1,2,3};
return;
end
%calculation here
[m,s];
end
Are you really sure that this is useful? The internally used names of the variables in the input list should not matter in the caller.
Youssef  Khmou
Youssef Khmou el 7 de Mzo. de 2013
Editada: Youssef Khmou el 7 de Mzo. de 2013
hi Micheal,
For example in C/C++, a header file contains predefined function such that including a header file ( example "math.h") in Main file imports the predefined functions, but here using Matlab, you can use nested functions and/ or external functions and /or Mex files written in C/C++ :
example :
%-------------------------------------------------
function Y=function_Name(a,b)
n=size(a);
% .......
% ........
Y=Mean_Modulus(a,b);
% Nested function
function Z=Mean_Modulus(a,b);
Z=mod(a,b);
Z=mean(Z(:));
return
%-------------------------------------------
So nested functions can replace header Files , that is my personal approach
I hope this helps

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 7 de Mzo. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by