How to call a user-defined function

I have a function, CAT(a,b,c) for example saved as CAT.m in a separate file. How can I call this user-defined function from the command window? When I use the function, it makes an error with the message, "Undefined variable or function". I checked for typos. Or rather, how would I put this file on the correct Matlab path? Thanks in advance.

2 件のコメント

Stephen23
Stephen23 2018 年 6 月 25 日
編集済み: Stephen23 2018 年 6 月 25 日
Make sure that the function is on the MATLAB Search Path (e.g. in the current folder):
Jisu Shin
Jisu Shin 2018 年 6 月 25 日
Thank you! Problem solved!

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

 採用された回答

dpb
dpb 2018 年 6 月 25 日

0 投票

Store it in the working directory or in a directory on MATLABPATH. Depending on what the function purpose is, specialized or more general, having a general directory for such functions that one keeps on the permanent path is a good technique. Besides CWD, I have a UTILITIES directory for precisely that purpose in the search path where that sort of thing goes.
I'd recommend to name your file something other than CAT(); even though Matlab is case-sensitive, the name being the same except for that to the builtin cat() function is bound to cause comprehension confusion later on, in nothing else.

1 件のコメント

Jisu Shin
Jisu Shin 2018 年 6 月 25 日
Thank you so much!!

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

2018 年 6 月 25 日

コメント済み:

2018 年 6 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by