creating a function without creating a class

2 ビュー (過去 30 日間)
JA
JA 2016 年 7 月 5 日
編集済み: per isakson 2016 年 7 月 7 日
Probably a stupid question, but i have a test file, which is just a set of commands and instantiation of some classes, but doesn't have any classes. I want to create a function in this file. Is it possible to create a function without having a class.
  1 件のコメント
Stephen23
Stephen23 2016 年 7 月 7 日
@Jagdish Ashok: if you are trying to define a function in the middle of a script then this will not works. Scripts and functions cannot be mixed together on one file.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 7 月 5 日
That just sounds like a regular function file to me. For example,
function test_it_out
s = serial('COM5'); %creates an object of class serial
t = vision.VideoReader('rhinos.avi'); %creates an object of class vision.VideoReader
  4 件のコメント
JA
JA 2016 年 7 月 5 日
Check the pic below, please
per isakson
per isakson 2016 年 7 月 7 日
編集済み: per isakson 2016 年 7 月 7 日
It's the documentation that's a bit "stupid". It doesn't clearly states that the line that declares a (primary/main) function must not be preceded by any executable lines - only by comments.
Your function, testfunc, will work nicely if you put it in a separate file.

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

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by