using a function in another m file

조회 수: 4 (최근 30일)
Altug
Altug 2012년 7월 9일
Hello,
I would like to know how you can use a function in another function.
e.g // function [ gam, alfa, beta] = att(L) should make use of the funciton s2abcd.m
abcd=s2abcd(data,50);
A= abcd(1,1,:);
I need to use that A matrix in another m file gam= cosh(A)/L; alfa=real(gam);
In C++ it can be done easily with include function but I dont know how you can do that in Matlab
Thanks in advance
  댓글 수: 1
Jan
Jan 2012년 7월 9일
Your comment to Luffy's answer shows, that your problem does not concern the access of the function at all. Therefore I strongly recommen to follow the standard procedure:
  1. Post the relevant code by copy&paste, such that even typos are replicated. Pseudo-code in the forum reduces the chance to find the error.
  2. Copy the complete error message including the line, which causes the error.

댓글을 달려면 로그인하십시오.

답변 (2개)

Luffy
Luffy 2012년 7월 9일
Just make sure the m-files in which both function & subfunction are in same directory.
  댓글 수: 1
Altug
Altug 2012년 7월 9일
편집: Altug 2012년 7월 9일
Actually both of them are in the same directory but still I get the following error message
***Undefined function or variable "abcd".
Error in att (line 4)
A= abcd(1,1,:); ***

댓글을 달려면 로그인하십시오.


Jan
Jan 2012년 7월 9일
As long as the other M-function is stored in a folder, which belongs to the Matlab PATH, or in the current folder (see cd command), you can calling the function works by using its name - as expected.
For adding a user-defined folder to the path type pathtool to the command window, or open the corresponding menu.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by