Calling function from different m-file

21 ビュー (過去 30 日間)
Rohit Kharat
Rohit Kharat 2022 年 1 月 19 日
回答済み: Image Analyst 2022 年 1 月 19 日
How to call a function present in a differemt m file to an existing working m file?

回答 (2 件)

Cris LaPierre
Cris LaPierre 2022 年 1 月 19 日
Call it by name. The file must be either in your current folder, or in a folder that has been added to your MATLAB path.
The calling syntax is your function declaration line (first line) of your function without the word 'function'. See here for more.
One thing to be aware of - the function can be the only thing in the file. No script at the top. In other words, you cannot call a local function defined at the bottom of a script from outside that script.
  3 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 1 月 19 日
Are you asking me? It looks good if you wanted to write a function. It appears to be calling a second function, luminance_NL.
Somewhere you have to call your function to run it.
Stephen23
Stephen23 2022 年 1 月 19 日
Note that your code will not call luminance_NL because Ch is a different variable to ch. Thus the error.
Do not ignore the underlining of ch, this is telling you very important information.

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


Image Analyst
Image Analyst 2022 年 1 月 19 日
Do you want inputImage to be gray scale, like
[row, col, numberOfColorChannels] = size(inputImage)
if numberOfColorChannels == 3
inputImage = rgb2gray(inputImage);
end
If you're really rather have your custom function luminance_NL() instead of rgb2gray(), then you'll have to use the "Set Path" button on the Home tab of the tool ribbon to add the folder where that function lives to the path.
The sum_pixel and threshold stuff can be done in a single line of code:
threshold = mean2(inputImage);

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by