Not enough input arguments - Function
2 ビュー (過去 30 日間)
古いコメントを表示
This is probably easy to spot and solve but I'm new to MATLAB so am having trouble with this.
I would greatly appreciate anybody proposing a solution to the function I have below. The error message is at the bottom and states that there are not enough input arguments. The variable 'data' is a single matrix with dimensions 9x52x2.
function X = CreateFeatures(data,fs,numCh);
% ==================================================================
% ============ Preallocations and definitions ======================
% ==================================================================
numF = 18; % Number of features
fs = 256;
numCh = 8;
X = zeros(1, numF*numCh); % Preallocate
% ==================================================================
% =================== Sub-functions ================================
% ==================================================================
function count = zerox(data) % sub-function: Zero-Crossings
t = 1:length(data)-1;
count = 0;
for i = 1:length(t)
if sign(data(i)) ~= sign(data(i+1))
count = count + 1;
end
end
end
function Ent = SpecEnt(data) % sub-function: Spectral Entropy
x = fftshift(fft(data));
PSD = abs(x).^2;
sum = 0;
for i = 1:length(data)
sum = sum + PSD(i);
end
PSDn = PSD/sum;
Ent = 0.0;
for i = 1:length(data)
Ent = Ent-PSDn(i)*log2(PSDn(i)+eps); % eps is the floating-point
% relative accuracy
end
end
function mob = Hjorth_mob(data) % sub-function: Mobility
h = 1; %step size for approximated derrivative
sd = var(data);
sdx = var(diff(data)/h); %sd of the first derivative of the signal
mob = sqrt(sdx/sd);
end
function com = Hjorth_com(data) % sub-function: Complexity
h = 1; %step size for approximated derrivative
sd = var(data);
xx = diff(data)/h;
sdx = var(xx); %sd of the first derivative of the signal
sdxx = var(diff(xx)/h);
com = sqrt((sdxx/sdx)/(sdx/sd));
end
% defining constants for input to the aar function below
Mode = [1,2]; % Mode = [aMode vMode]
MOP = [5,0]; % model order (number of parameters = 5)
% ===================================================================
% =============== Creating the feature vector =======================
% ===================================================================
for j = 0:numCh-1 % Loop over channels
X(numF*j+1) = log10(var(data(j+1,:))); % Hjorth: activity (variance)
X(numF*j+2) = zerox(data(j+1,:)); % Zero-crossings
X(numF*j+3) = SpecEnt(data(j+1,:)); % Spectral entropy
X(numF*j+4) = log10(abs(wentropy(data(j+1,:),'shannon'))); % Shannon entropy
X(numF*j+5) = log10(Hjorth_mob(data(j+1,:))); % Hjort: mobility
X(numF*j+6) = log10(Hjorth_com(data(j+1,:))); % Hjort: complexity
AllParam = aar(data(j+1,:)', Mode, MOP)' ; % finding all AAR
% parameters using function from Biosig
X(numF*j+(7:11)) = mean(AllParam(:,6:end),2); % mean over each row
% (5 AAR param/channel)
X(numF*j+12) = log10(bandpower(data(j+1,:),fs,[0.5 4])); % BP delta
X(numF*j+13) = log10(bandpower(data(j+1,:),fs,[4 8])); % BP theta
X(numF*j+14) = log10(bandpower(data(j+1,:),fs,[8 13])); % BP alpha
X(numF*j+15) = log10(bandpower(data(j+1,:),fs,[14 30])); % BP beta
X(numF*j+16) = log10(bandpower(data(j+1,:),fs,[31 70])); % BP gamma
X(numF*j+17) = log10(bandpower(data(j+1,:),fs,[71 100])); % BP high gamma
X(numF*j+18) = log10(bandpower(data(j+1,:),fs,[0.5 100])+eps); % BP total
end
end
The error message reads:
>> CreateFeatures
Not enough input arguments.
Error in CreateFeatures (line 88)
X(j) = log10(var(data(j+1,:))); % Hjorth: activity (variance)
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 8 月 27 日
You define
function X = CreateFeatures(data,fs,numCh);
so CreateFeatures is a function with up to 3 inputs. But you invoke
>> CreateFeatures
which passes no inputs. The code fails at the first place that it refers to one of the three input parameters and discovers that you did not pass in that argument.
2 件のコメント
Walter Roberson
2016 年 8 月 28 日
I copied your code in to my system and invoked
CreateFeatures(1:50)
Only 1 argument is needed here because you overwrite the contents of the other two arguments at the very beginning of your code.
The code did not fail with "not enough input arguments". Instead it failed with
Undefined function or variable 'aar'.
Error in CreateFeatures (line 115)
AllParam = aar(data(j+1,:)', Mode, MOP)' ; % finding all AAR
aar() is not part of MATLAB and does not appear to be part of the File Exchange either.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!