Want to create subclass of Dataset class in Stats Toolbox: How do I pass arguments to dataset constructor in constructor for new class?

1 view (last 30 days)
How to I pass arguments to the constructor spec = spec@dataset(input); I want to have the full range of input options available to the normal dataset class. That is multiple inputs of the form: DS = DATASET(..., {DATA,'name'}, ...)
Should I be trying to create a string for the input argument and passing it using the EVAL(s) function?
classdef ramandataset < dataset
properties
ExperimentID
SampleID
ExciteWavelength
DateTaken
Apparatus
end
methods
function spec = ramandataset(data,names)
%RAMANDATASET Class Constuctor
% INPUT DATA: spec = ramandataset(data,names);
% where data is a double matrix of the form
% **********
% k ri k ri k ri
% **********
% and names is a 1 by n cell array of strings
if nargin == 0
super_args{1} = [0];
super_args{2} = '';
else
for i=1:size(data,2)/2
input = [];
super_args{1} = data(:,2*i-1:2*i);
super_args{2} = names{i};
input = {input super_args};
end %END FOR
end %END IF
spec = spec@dataset(input); %MY PROBLEM IS IN THIS LINE I THINK
end % END CONSTRUCTOR
end % END METHODS
methods
% % OVERLOADING
end
end % END CLASSDEF
Any advice would be most appreciated.
  1 Comment
Justin
Justin on 30 Aug 2011
Sorry forgot to mention:
I am trying to pass the following arguments:
data = [sample_10_dried sample_11_dried sample_12_dried];
names = {'sample10','sample11','sample12'};
where each sample_1*_dried is a 1600x2 double array.
trying to construct instance of ramandataset:
instance = ramandataset(data,names)
The output I get is:
instance =
input
[ ] {1x2 cell}
thanks!

Sign in to comment.

Accepted Answer

owr
owr on 30 Aug 2011
I'm not sure what exactly you are trying to do but if you want the full constructor capabilities of the dataset class you will need to allow your own class to take in a variable number of input arguments. So you'll need to use "varargin".
A second thing that might hold you up (it held me up) is how to pass a variable size cell array to the dataset constructor. You have to use "{:}" on the input.
Here's a very simple example:
classdef ramandataset < dataset
properties
end
methods
function spec = ramandataset(varargin)
spec = spec@dataset(varargin{:});
end % END CONSTRUCTOR
end % END METHODS
end
Heres an exmaple to test this:
data1 = randn(10,1);
data2 = randn(10,1);
ds = ramandataset({data1,'data1'},{data2,'data2'})
I'd start with this and add your custom modifications as you see fit. I'd also expect to overload the subsref and subsasgn functions.
It might take some time to get it all right but its been very worthwhile for my own work. I hope this helps a bit.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!