Convert folder of functions - > Class folder

I have a folder full of functions and I would like to turn it into a class folder.
example: my folder of function has
func1.m
func2.m
func3.m
Currently I have dumped all the function signatures into a class method.
classdef myclassname<handle
% properties blah blah
% constructor here etc etc
methods (Static)
func1()
func2()
func3()
end
end
end
These functions call out other functions and I would have to create dot notation each time, ex:
function func1()
myclassname.func2
myclassname.func3
end
Now, I have more than 50 functions. I dont want to keep looking around to find out where I need to put the class handle and dot wherever a function within myclass folder is being called -- Is there something more efficient that will do all of that for me?

7 件のコメント

Steven Lord
Steven Lord 2019 年 2 月 7 日
I have a folder full of functions and I would like to turn it into a class folder.
Can you say a little more about why you want to turn the folder full of functions into a class? What benefit do you hope to gain by doing so?
Walter Roberson
Walter Roberson 2019 年 2 月 7 日
perhaps you should consider creating a package instead of a class and then import the package .
Matt J
Matt J 2019 年 2 月 7 日
I don't think packaging the files will help, unfortunately. Packaged functions still need to refer to each other using package.func syntax.
Guillaume
Guillaume 2019 年 2 月 7 日
Yes, you still need to refer to the prepend the name of the package, even within the package scope. A very annoying feature of matlab.
However, in this case, you could just add an import packagename.* to the start of each function. Less painful than trying to locate each function call.
Kevin Phung
Kevin Phung 2019 年 2 月 7 日
編集済み: Kevin Phung 2019 年 2 月 7 日
Thanks for the responses, I'll read up on packaging files and see how if it will help my situation--
@Steven Lord I should have been more specific, I'm creating an HMI and it would just be a lot more organized to contain all the callback functions into a class, so I have a mix of static and non static functions
Steven Lord
Steven Lord 2019 年 2 月 7 日
You may be interested in App Designer if you're not already using it.
Kevin Phung
Kevin Phung 2019 年 2 月 7 日
編集済み: Kevin Phung 2019 年 2 月 7 日
@Steven
As aesthetic and convenient App Designer is, it does not support some functionalities that I want-- so I'm doing it programmatically

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

 採用された回答

Matt J
Matt J 2019 年 2 月 7 日
編集済み: Matt J 2019 年 2 月 7 日

1 投票

One solution would be to move all the functions to a private/ sub-folder within the @myclassname folder. Then, assuming you still even need static versions of those functions, you can simply add aliases for them in a Static methods block:
methods (Static)
function varargout=func1(varargin)
[varargout{1:nargout}]=func1(varargin{:}); %calls @myclassname/private/func1
end
function varargout=func2(varargin)
[varargout{1:nargout}]=func2(varargin{:}); %calls @myclassname/private/func2
end
function varargout=func3(varargin)
[varargout{1:nargout}]=func3(varargin{:}); %calls @myclassname/private/func3
end
...
end

1 件のコメント

Kevin Phung
Kevin Phung 2019 年 2 月 7 日
this works!!
Thank you

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

その他の回答 (0 件)

カテゴリ

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

製品

質問済み:

2019 年 2 月 7 日

編集済み:

2019 年 2 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by