how to access abstract class in matlab
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhammad Khalid
am 11 Aug. 2019
Kommentiert: per isakson
am 14 Aug. 2019
Hi,
how can i access this abstract class i had lote of try to access this abstract class directly and indirectly .when i try this indirectly make object it give error of <Error displaying value > and when i access direclt it give error in calling obj@featureGenerationUnit
thanks already
classdef asymmetryFeatures < featureGenerationUnit
properties
psd;
de;
EEG;
INFO;
end
methods
% Constructor calls super
function obj = asymmetryFeatures(EEG, INFO)
obj@featureGenerationUnit(EEG, INFO);
obj.addDE();
end
%%Takes in a 2D matrix of channels versus raw EEG and computes
%%the psd over given frequency bands in the INFO datafile
function [psdPerBand] = getPSD(obj, data)
%get data dimensions
[nChannels, N] = size(data);
%psd = zeros(nChannels,size(obj.INFO.bands.names,2));
%compute raw power sprectral density (psd)
xdft = fft(data, N, 2);
xdft = xdft(:,1:N/2+1);
psd = (1/(obj.INFO.fs*N)) * abs(xdft).^2;
%take away mirrored data
psd(:,2:end-1) = 2*psd(:,2:end-1);
%Get indexes for frequency band cutoffs
INFO.bands.i = obj.INFO.bands.freq.*(size(psd,2)-1)/(obj.INFO.fs/2);
nBands = size(obj.INFO.bands.freq,1);
psdPerBand = zeros(nChannels,nBands);
for band = 1:nBands
%Get indexes of interest
name = char(obj.INFO.bands.names(band));
i1 = obj.INFO.bands.freq(band,1);
i2 = obj.INFO.bands.freq(band,2);
%number of points used in calculation
point_num = abs(i2 - i1);
%compute mid freq for each band (plotting)
INFO.bands.med(band) = i1 + (i2-i1)/2;
%index PSD matrix for given band
band_data = psd(:,i1:i2);
%Calculate average power over band for each channel
psdPerBand(:,band) = sum(band_data,2)./point_num;
end
end
function addPSD(obj)
obj.psd = zeros(obj.EEG.nbchan,obj.INFO.bands.n,obj.INFO.epochs);
for epoch = 1:obj.INFO.epochs
obj.psd(:,:,epoch) = obj.getPSD(obj.EEG.data(:,:,epoch));
end
end
function addDE(obj)
if(size(obj.psd)>0)
obj.de = log(obj.psd);
else
obj.addPSD()
obj.de = log(obj.psd);
end
end
function [features, names] = doOnPairsByBands(obj, data, operation, pairs, operationName)
% if string pairs, map to numbers
if(iscell(pairs))
pairs = arrayfun(@(x) obj.INFO.channelMap(x{1}),[pairs(:,1),pairs(:,2)]);
end
nPairs = size(pairs,1);
[~, nBands] = size(data);
nFeatures = nPairs*nBands;
features = zeros(nFeatures,1);
names = cell(nFeatures,1);
count = 0;
for i=1:nPairs
%disp(assymPairs{i,1})
for band = 1:nBands
count = count + 1;
left = pairs(i,1);
right = pairs(i,2);
features(count,:) = operation(data(left,band), data(right,band));
mapChan = @(x) obj.INFO.reverseMap(x);
bandMap = @(x) obj.INFO.bands.names{x};
names{count} = strcat(mapChan(left),'-',mapChan(right),'-',bandMap(band),'-',operationName);
end
end
end
function [features, sampleNames] = forAllEpochs(obj,func,data,operation,pairs,operationName)
%get size
epochs = obj.INFO.epochs;
[sampleFeature,sampleNames] = func(data(:,:,1), operation,pairs,operationName);
features = zeros([epochs size(sampleFeature)]);
for epoch = 1:epochs
[features(epoch,:),~] = func(data(:,:,epoch), operation,pairs,operationName);
end
end
function processPairs(obj,data, operation, pairs, operationName)
[features,names] = obj.forAllEpochs(@obj.doOnPairsByBands,data,operation,pairs,operationName);
obj.addFeaturesAndNames(features,names);
end
function addPSDfeatures(obj)
if(size(obj.psd) == 0)
obj.addPSD();
end
[nChannels,nBands, epochs] = size(obj.psd);
names = (strcat(...
(arrayfun(@(x) obj.INFO.reverseMap(x),repmat([1:nChannels],1,nBands),'UniformOutput',false)),'-',...
arrayfun(@(x) obj.INFO.bands.names{x},reshape(repmat([1:nBands],1,nChannels),1,[]),'UniformOutput',false)...
,'-psd'))';
dims = size(obj.psd);
features = reshape(permute(obj.psd,[3,2,1]),dims(3),dims(1)*dims(2));
obj.addFeaturesAndNames(features,names);
end
function addDEfeatures(obj)
if(size(obj.de) == 0)
obj.addDE();
end
[nChannels,nBands, epochs] = size(obj.de);
names = (strcat(...
(arrayfun(@(x) obj.INFO.reverseMap(x),repmat([1:nChannels],1,nBands),'UniformOutput',false)),'-',...
arrayfun(@(x) obj.INFO.bands.names{x},reshape(repmat([1:nBands],1,nChannels),1,[]),'UniformOutput',false)...
,'-de'))';
dims = size(obj.de);
features = reshape(permute(obj.de,[3,1,2]),dims(3),dims(1)*dims(2));
obj.addFeaturesAndNames(features,names);
end
function addDASMfeatures(obj)
obj.processPairs(obj.de, @gsubtract, obj.INFO.pairs.lateral, 'sub');
end
function addDCAUfeatures(obj)
obj.processPairs(obj.de, @gsubtract, obj.INFO.pairs.caudal, 'sub');
end
function addRASMfeatures(obj)
obj.processPairs(obj.de, @gdivide, obj.INFO.pairs.lateral, 'div');
end
function addALLfeatures(obj)
N = size(obj.de,1);
count = 0;
pairs = zeros(N*(N-1)/2,2);
for i = 1:N
for j = i+1:N
count = count + 1;
pairs(count,:) = [i, j];
end
end
obj.processPairs(obj.de, @gsubtract, pairs, 'sub');
end
function [features,names] = getClassic(obj)
obj.addPSDfeatures();
obj.addDEfeatures();
obj.addDASMfeatures();
obj.addDCAUfeatures();
obj.addRASMfeatures();
features = obj.features;
names = obj.names;
end
function[features,names] = getAll(obj)
obj.addDEfeatures();
obj.addALLfeatures();
features = obj.features;
names = obj.names;
end
function[features,names] = getDE(obj)
obj.addDEfeatures();
features = obj.features;
names = obj.names;
end
function addFeaturesAndNames(obj, newFeatures, newNames)
if(size(obj.features,1) > 0)
obj.features = horzcat(obj.features, newFeatures);
else
obj.features = newFeatures;
end
if(size(obj.names,1) > 0)
obj.names = cat(1, obj.names, newNames);
else
obj.names = newNames;
end
end
function [features] = getFeatures(obj)
features = obj.features;
end
end
end
.
% inherets from handle to work with reference
classdef (Abstract) featureGenerationUnit < handle
properties
EEG;
features;
names;
INFO;
status;
end
methods
function obj = featureGenerationUnit(EEG, INFO)
obj.EEG = EEG;
obj.INFO = INFO;
end
function loadData(EEG)
obj.EEG = EGG;
end
function loadInfo(INFO)
obj.INFO = INFO;
end
end
methods(Abstract)
getFeatures(obj)
end
end
3 Kommentare
Guillaume
am 14 Aug. 2019
@Muhammad, use comments to add additional information. Do not use Answer this question for that. Your question now has 4 answers, included one accepted, so nobody is going to bother looking at it, thinking: "well it already has 4 answers, one has been accepted, there's probably nothing more to say".
So, please delete your answers and post them as comment to your question (or the answer you've accepted), as I've done here.
Akzeptierte Antwort
per isakson
am 12 Aug. 2019
Bearbeitet: per isakson
am 12 Aug. 2019
I'm not sure, I exactly understand what you mean. However, I try
"how can I access this abstract class" You cannot "access" an abstract class "directly".
>> fGU = featureGenerationUnit(EEG,INFO)
Abstract classes cannot be instantiated. Class 'featureGenerationUnit' defines
abstract methods and/or properties.
"indirectly" you can "access" it by creating an instance of its subclass, asymmetryFeatures.
There are several mistakes in your code, e.g. defining EEG and INFO in the subclass.
If you want further help you need to supply values of EEG and INFO.
/R2018b
0 Kommentare
Weitere Antworten (3)
Muhammad Khalid
am 13 Aug. 2019
1 Kommentar
per isakson
am 13 Aug. 2019
Bearbeitet: per isakson
am 14 Aug. 2019
The method, addPSD, indicates that EEG is a struct with two fields, nbchan and data. Table11.txt contains one column of numbers.
function addPSD(obj)
obj.psd = zeros(obj.EEG.nbchan,obj.INFO.bands.n,obj.INFO.epochs);
for epoch = 1:obj.INFO.epochs
obj.psd(:,:,epoch) = obj.getPSD(obj.EEG.data(:,:,epoch));
end
end
How shall the column of numbers be assigned to EEG.data?
Muhammad Khalid
am 14 Aug. 2019
1 Kommentar
per isakson
am 14 Aug. 2019
This is a new question. I has no answer. Post a new question and tag it "EEGLAB".
Siehe auch
Kategorien
Mehr zu EEG/MEG/ECoG finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!