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 件のコメント
I cannot imagine in which situation this could be useful. What does "header" exactly mean and how does it "give"?
回答 (2 件)
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
2013 年 3 月 7 日
編集済み: Youssef Khmou
2013 年 3 月 7 日
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
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!