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 Comments

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.)
What do you mean is the old way?What's the newer style?

Sign in to comment.

 Accepted Answer

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 Comment

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

Sign in to comment.

More Answers (1)

Daniel Shub
Daniel Shub on 10 Oct 2011
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:

Asked:

on 10 Oct 2011

Community Treasure Hunt

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

Start Hunting!