Call a portion of one function from another one

I wrote a relatively large code for analyzing an image, which contains several smaller functions that are called in a big loop. It also includes the uigetfile function at the beginning to select the input image. What I need to do is create another function (new .m file) that calls the above function to analyze a list of images identified in a directory using uigetdir. How can I do that? In short, the new function should only call specific portions of the other code (avoid uigetfile and possibly other smaller parts).

回答 (1 件)

Timmy
Timmy 2015 年 1 月 15 日

0 投票

You can only call the (main) function that is the name of the .m file. If you need to call a sub-function from that main function file, you need to create a new .m file for the sub-function or copy-and-paste into the other main function file.
for example, you have this file:
main1.m
function main1
function subfuction1
function subfuction2
You want to call subfunction1 in your main2.m, you can either copy-and-paste the subfunction1 into main2.m or create a subfunction1.m

1 件のコメント

Xen
Xen 2015 年 1 月 15 日
編集済み: Xen 2015 年 1 月 15 日
Thanks Timmy. I was hoping for a way to call an .m file, say from line 15 to line 200! That would be really handy and make coding more concise. I have read that function handles can be useful, but never used them before so I'll just follow your suggestion.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

Xen
2015 年 1 月 15 日

編集済み:

Xen
2015 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by