Folders Structure in OOP in matlab

Hi,
I would like to ask you if it is possible to have a structure in matlab like the one below
mainpath/@fld1
mainpath/@fld1/fld1.m
mainpath/@fld1/@subfld11
mainpath/@fld1/@subfld11/subfld11.m
mainpath/@fld1/@subfld12/
mainpath/@fld1/@subfld12/subfld12.m
mainpath/@fld1/@subfld13/
mainpath/@fld1/@subfld13/subfld13.m
...
What I would like is to organize my code in such a way so that I could understand that subfld11 is part of fld1 (not subclass) and that fld1 (class) can use subfld11 methods/properties etc.
Thanks in advance

2 Commenti

Hmmmm, maybe, but the '@' folder structure was the old style of OOP; you have more control with the newer style (which has been around since roughly 2009a I think it was.)
Simeon
Simeon il 11 Ott 2011
What do you mean is the old way?What's the newer style?

Accedi per commentare.

 Risposta accettata

Simeon
Simeon il 11 Ott 2011
Thanks Daniel,
I thinks that the package is the most appropriate one. However the syntax of a class is much more convenient. I have to write the whole path in order to enter a subfolder.
mainpath/fld1
mainpath/fld1/fld1.m
mainpath/fld1/@subfld11
mainpath/fld1/@subfld11/subfld11.m
mainpath/fld1/subfld12/
mainpath/fld1/subfld12/subfld12.m
mainpath/fld1/subfld12/@subfld121
mainpath/fld1/subfld12/@subfld121/subfld121.m
mainpath/fld1/subfld12/@subfld122
mainpath/fld1/subfld12/@subfld122/subfld121.m
mainpath/fld1/@subfld13/
mainpath/fld1/@subfld13/subfld13.m
...
So in my example I have to write for instance
a = fld1.fld1();
b = fld1.subfld12.subfld121();
What if I want to call a function in subfld121 from subfld12? Should I write again the whole path?
c = fld1.subfld12.subfld121();
or
c = subfld121();
Thanks in advance

1 Commento

With packages you can import the fuctions from the package. If you import many packages you need to worry about name conflicts.

Accedi per commentare.

Più risposte (1)

Daniel Shub
Daniel Shub il 10 Ott 2011

0 voti

You cannot do that. From the documentation ( http://www.mathworks.co.uk/help/techdoc/matlab_oop/brfynrp-1.html):
@-folders — Folder name begins with "@" and is not on the MATLAB path, but its parent folder is on the path.
So your second level of @ folders would not have parents who are on the path.
You might want to look into a package:

Categorie

Scopri di più su Simulink Coder in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by