Azzera filtri
Azzera filtri

Dynamic Properties in Variable Editor and mixed subclasses question

1 visualizzazione (ultimi 30 giorni)
So I've created a class to load some data files for my work. I plan to share this so that others can integrate it into their code. The problem is that we have several different data file formats from all over the place and covering several years (there's csv files, ASSET files, Excel files, data files from homegrown software (both column and row based, tab or space delimited, etc.), and more). What's more, different file types are often tied together (e.g. some data is stored in an ASSET file while more detailed data is stored a file generated by custom software).
Needless, to say, my class is quite complex, mostly just because it has to be to support so many different file structures. Originally, I created a general superclass, and each type of file format had its own subclass. This worked pretty well, but one issue I had is that, since files are often linked, I would like to use arrays of objects, which obviously can't be done unless all objects are of the same class.
This brings me to my first question: What is the easiest way to have separate subclasses, but objects of the different subclasses simply become objects of the superclass when the superclass' constructor is called? I seem to remember reading something about this, but I've forgotten... Should I simply create a subclass object in the superclass' constructor method, then copy over the properties to a superclass object and destroy the original object? That seems like a poor way to do things, not to mention a waste of resources and loss of inheritance, which would be the whole point of using subclasses anyway. I suppose I could just use structures or cell arrays of object handles instead, but object arrays are pretty convenient for some things.
Anyway, to get around this a bit more easily (and to simplify my file structure a bit), I decided to instead transition to a 'performance_datafile' class that simply has several utility methods to determine what the filetype of a given file is during the constructor call and load it accordingly. It also modifies it to a specified layout if necessary. The problem I have is that one specific type of data file that we use has two header rows (the name of the column, then the units of the data), while all others simply have one (the name). For obvious reasons, I don't want to get rid of the units, but I also don't want to create a class property just for this type of data file (that is sparsely used by most people anyway) that will usually remain empty.
My first thought was to just concatenate them into one header (i.e. header{1} = [name, ' - ',units]). Problem with that is that the data is often converted into different units anyway, so leaving the original units could cause confusion if the header is used for DisplayName or some related purpose. So what I did to get around this was make my class a subclass of 'dynamicprops' and issue an addprop(obj,'unitheader') command when this particular data type is loaded. This works well and I can access the added property just fine, but it doesn't show up in the Variable Editor. This is confusing for users, even ones that are experienced in MATLAB but don't have much background on my code (issuing a 'properties' function isn't exactly the first thing that comes to mind when using an object, especially if you don't even know that there's a missing property). Is there any way around this?
Thanks in advance.

Risposte (0)

Categorie

Scopri di più su Properties in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by