Let an Object Instance work on Calling Object
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello MatLabers
I'm trying to implement some simple Matlab OO classes: I have one class (DataLoader) with a method/function (loadABCData) and another class (DataSet) with attributes/properties (stream, nfiles, stuff) as well as methods (loadData, doSomeCalc).
What I would like to do: Is to be able to do something like the following:
myDS = DataSet; % get that new Object
myDs.loadData; % load Data using a DataLoaderObject
so that I finally can access the properties of my object that have been filled in by my DataLoaderObject i.e.:
foo = myDS.stream(:,1:3);
What I have so far:
The data loading is done in the DataLoader.loadABCData function that I have located in loadABCData.m (Folder: @DataLoader). The implementation of DataSet.loadData looks as follows:
function loadData(obj)
loader = DataLoader; % make the DataLoader Object for Reading
loader.loadABCData(obj); % call the loadABCData and give it the handle
% to the original Object where I would like to
% have the Data filled in
delete(loader); % remove my DataLoader again
end
in the DataLoader itself, the loadABCData function looks somehow like this:
function loadABCData(obj, dataset)
variableFromDataSet = dataset.nfiles;
fid = fopen...
...
dataset.stream = someDataFromFile;
...
fclose(fid);
dataset.stuff = 12;
end
This however does not work (i.e. does not fill my objects properties)
I tried to do the following
function dataset = loadABCData(obj, dataset)
...
end
with
function loadData(obj)
loader = DataLoader;
obj = loader.loadABCData(obj);
as well as
function obj = loadData(obj)
loader = DataLoader;
obj = loader.loadABCData(obj);
latter gives me the filled in object in ans but does not assign it to the calling object. I'm new to Matlab OO programming - do however know how things work in other languages. Does anyone of you know how I can implement what I would like to?
Any help is very much appreciated on this. Thank you!
ps. all my classes are handle classes (< handle) pps. the following works, is however not what I aim for (i.e. I want the object to handle the loading itself and do not want to do this at the level where I create the object):
dl = DataLoader;
ds = DataLoader.loadABCData;
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!