Convert folder of functions - > Class folder

18 vues (au cours des 30 derniers jours)
Kevin Phung
Kevin Phung le 7 Fév 2019
Modifié(e) : Kevin Phung le 7 Fév 2019
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 commentaires
Steven Lord
Steven Lord le 7 Fév 2019
You may be interested in App Designer if you're not already using it.
Kevin Phung
Kevin Phung le 7 Fév 2019
Modifié(e) : Kevin Phung le 7 Fév 2019
@Steven
As aesthetic and convenient App Designer is, it does not support some functionalities that I want-- so I'm doing it programmatically

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 7 Fév 2019
Modifié(e) : Matt J le 7 Fév 2019
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 commentaire
Kevin Phung
Kevin Phung le 7 Fév 2019
this works!!
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by