I have been getting this error and have had no luck resolving it. Any help please?

7 views (last 30 days)
>> addwaves3(a, 'db2') Error: File: addwaves3.m Line: 32 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "addwaves3".)
this is the code for the function attached.
function addwaves3(input, wavelet)
% Get the Daubechies2 wavelet/scaling coeffs
% if wavelet == 'db2'
if (strcmp(wavelet,'db2'))
[LPF, HPF, ILPF, IHPF] = myDB2;
else
[LPF, HPF, ILPF, IHPF] = myHaar;
end
% Do the wavelet transform
L = downsample(myconv(input, LPF));
H = downsample(myconv(input, HPF));
%[LL, LH] = dwt(L);
LL = downsample(myconv(L, LPF));
LH = downsample(myconv(L, HPF));
%[LLL, LLH] = dwt(LL);
LLL = downsample(myconv(LL, LPF));
LLH = downsample(myconv(LL, HPF));
% L is not needed anymore, nor is LL
clear L LL
% Get the waves for each sub-signals contribution
if (strcmp(wavelet,'db2'))
% The ILow and IHigh functions are hard-coded for db2.
wave1 = ILow(ILow(ILow(LLL)));
wave2 = ILow(ILow(IHigh(LLH)));
wave3 = ILow(IHigh(LH));
wave4 = IHigh(H);
else
% The ILowHaar and IHighHaar functions are hard-coded for haar.
wave1 = ILowHaar(ILowHaar(ILowHaar(LLL)));
wave2 = ILowHaar(ILowHaar(IHighHaar(LLH)));
wave3 = ILowHaar(IHighHaar(LH));
wave4 = IHighHaar(H);
end
% The signal above needs to be padded (made longer).
% First, find the longest length.
max_len = max(max(length(wave1), length(wave2)), ...
max(length(wave3), length(wave4)));
% Now adjust the signals, as needed
if (length(wave1) < max_len)
wave1(length(wave1)+1:max_len) = 0;
end
if (length(wave2) < max_len)
wave2(length(wave2)+1:max_len) = 0;
end
if (length(wave3) < max_len)
wave3(length(wave3)+1:max_len) = 0;
end
if (length(wave4) < max_len)
wave4(length(wave4)+1:max_len) = 0;
end
% Add all the waves together
waves = wave1 + wave2 + wave3 + wave4;
% Make the input the same length as the output
% do this by truncating the output
output = waves(1:length(input));
disp(sprintf('The total error between input and output is %10.9f.', ...
sum(abs(input - output))));
% Now plot the results.
figure(1);
subplot(4,1,1);
plot(wave4);
%plot100to1(wave4);
title('High wave (level 1 detail)');
subplot(4,1,2);
plot(wave3);
%plot100to1(wave3);
title('Low-High wave (level 2 detail)');
subplot(4,1,3);
plot(wave2);
%plot100to1(wave2);
title('Low-Low-High wave (level 3 detail)');
subplot(4,1,4);
plot(wave1);
%plot100to1(wave1);
title('Low-Low-Low wave (level 3 approximation)');
figure(2);
subplot(2,1,1);
plot(input);
%plot100to1(input);
title('Input Signal');
subplot(2,1,2);
%plot(1:length(output), output, 'b', 1:length(input), input, 'r');
plot(output);
%plot100to1(output);
title('Reconstructed signal (sum of previous fig)');
Thanks

Accepted Answer

Iain
Iain on 2 Sep 2013
(It follows the END that terminates the definition of the function "addwaves3".)
Thats your major clue:
function ...
%code here
end
addwaves3(a, 'db2')
The error is that you end the function before some more real code. You may either:
Comment out the extra real code if you don't want it to do anything
Remove an incorrect end
Put the extra real code inside another function
function ...
%code here
addwaves3(a, 'db2')
function ...
%code here
end
% addwaves3(a, 'db2')
function ...
%code here
end
function trashcan
addwaves3(a, 'db2')
end

More Answers (0)

Categories

Find more on Discrete Multiresolution Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!