Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

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

1 Ansicht (letzte 30 Tage)
kajalschopra
kajalschopra am 27 Jul. 2015
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 27 Jul. 2015
Yes it's possible. Before asking, you could just try it.

Antworten (1)

Walter Roberson
Walter Roberson am 27 Jul. 2015
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.

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by