Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

calling a function from.m file A - the function is in .m file B

조회 수: 1 (최근 30일)
kajalschopra
kajalschopra 2015년 7월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
I have a function Fn_A defined in a .m file (say file1.m)
I have another function FN_B defined in a .m file (say file2.m)
I want to call Fn_B from Fn_A. Is it possible?
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 27일
Yes it's possible. Before asking, you could just try it.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 7월 27일
In order to easily call a function from another file, the function must the the first in the second file and the file must be named for the function. In such a case you just call the function normally.
If the function is not the first one in the second file, then in order for the first file to be able to invoke the function, it first needs to have a function handle to the second function. There is no way to generate that handle from outside the second file: you would have to have the first function in that second file construct the handle and make it available to the first function (such as by returning it, or by saving it in a known location such as by using the handles structure)
It is time for you to think about splitting apart that second file.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by