please help i am having a problem debugging my code. the error is Function definitions are not permitted in this context.
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
i am having a problem debugging my code. the error is Function definitions are not permitted in this context.
this is my code:
clc;
clear all;
% EMD: Emprical mode decomposition
%
% imf = emd(x,n)
%
% x - input signal (must be a column vector)
% n - number of intrinsic mode functions
%
% imf - Matrix of intrinsic mode functions (each as a row)
%
% See: Huang et al, Royal Society Proceedings on Math, Physical,
% and Engineering Sciences, vol. 454, no. 1971, pp. 903-995,
% 8 March 1998
%
% Author: Ivan Magrin-Chagnolleau <ivan@ieee.org>
%
x=[ ...; ...
-8; ...
-22; ...
-34; ...
-12; ...
-32; ...
-34; ...
-12; ...
-26; ...
-58; ...
-12; ...
-26; ...
-34; ...
-16; ...
-2; ...
-20; ...
-8; ...
6; ...
-26; ...
-14; ...
10; ...
2; ...
-8; ...
16; ...
14; ...
-4; ...
-8; ...
-16; ...
-36; ...
-58; ...
-26; ...
-24; ...
-52; ...
-32; ...
-14; ...
-50; ...
-48; ...
-14; ...
-48; ...
-34; ...
34; ...
160; ...
298; ...
-8; ...
-18; ...
12; ...
2; ...
-30]; ...
plot(x);
function imf = emd(x,n)
c = x(:)';
N = length(x);
imf = [];
for t=1:n
h = c;
SD = 1;
while SD > 0.3
d = diff(h);
maxmin = [];
for i=1:N-2
if d(i)==0
if sign(d(i-1))~=sign(d(i+1))
maxmin = [maxmin, i];
end
elseif sign(d(i))~=sign(d(i+1))
maxmin = [maxmin, i+1];
end
end
if size(maxmin,2) < 2
break
end
if maxmin(1)>maxmin(2)
maxes = maxmin(1:2:length(maxmin));
mins = maxmin(2:2:length(maxmin));
else
maxes = maxmin(2:2:length(maxmin));
mins = maxmin(1:2:length(maxmin));
end
maxes = [1 maxes N];
mins = [1 mins N];
maxenv = spline(maxes,h(maxes),1:N);
minenv = spline(mins, h(mins),1:N);
m = (maxenv + minenv)/2; % mean of max and min enveloppes
prevh = h; % copy of the previous value of h before modifying it
h = h - m; % substract mean to h
% calculate standard deviation
eps = 0.0000001; % to avoid zero values
SD = sum ( ((prevh - h).^2) ./ (prevh.^2 + eps) );
end
imf = [imf; h];
if size(maxmin,2) < 2
break
end
c = c - h;
end
return
Respuestas (1)
dpb
el 26 de Jun. de 2014
You must put the code for the function emd in a file named emd.m The first line in the file is the function definition line.
Then put the script in another script file that calls the function. BTW, remove clc; clear all; from the script file--it'll likely create more havoc than issues it solves in debugging and retaining your results for later use.
See
doc function
and the general section on Programming Scripts and Functions for details and the specific differences between them.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!