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!