Too many output arguments error in my code

조회 수: 5 (최근 30일)
Robert
Robert 2015년 6월 2일
편집: Stephen23 2015년 6월 2일
I have the following code, I am trying to get all of the wavelet approximations out (it works fine with details, but not approximations).
I know what the error means, I just can't figure out how it applies in my code.
GRACE = load ('GRACE.txt')
ncol = size(GRACE,2);
for k = 1:ncol
[c,l] = wavedec(GRACE(:,k),6,'dmey');
cA6 = appcoef(c,l,'dmey',6);
[cD1,cD2,cD3,cD4,cD5,cD6] = appcoef(c,l,[1,2,3,4,5,6]);
D = [];
D(:,6) = wrcoef('d',c,l,'dmey',6);
D(:,5) = wrcoef('d',c,l,'dmey',5);
D(:,4) = wrcoef('d',c,l,'dmey',4);
D(:,3) = wrcoef('d',c,l,'dmey',3);
D(:,2) = wrcoef('d',c,l,'dmey',2);
D(:,1) = wrcoef('d',c,l,'dmey',1);
filename = sprintf('%s_%04f.txt', 'GRACE_APROXIMATIONS', k)
csvwrite(filename,D)
end
Any help would be greatly appreciated

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 2일
편집: Walter Roberson 2015년 6월 2일
appcoef() only ever returns one variable. You are trying to get it to return 6.
If you are not passing a string representing the wavelet name, then you should be using either 4 or 5 arguments, with the 3rd and 4th being filters. Your [1,2,3,4,5,6] is being interpreted as a filter.
You cannot pass in a list of levels and get one output variable for each.
  댓글 수: 4
Robert
Robert 2015년 6월 2일
So something like this? This is my best interpretation of what you suggest, Still I get the same error, am I on the right path?
GRACE = load ('GRACE.txt')
ncol = size(GRACE,2);
for k = 1:ncol
[c,l] = wavedec(GRACE(:,k),6,'dmey');
cA1 = appcoef(c,l,'dmey',1);
cA2 = appcoef(c,l,'dmey',2);
cA3 = appcoef(c,l,'dmey',3);
cA4 = appcoef(c,l,'dmey',4);
cA5 = appcoef(c,l,'dmey',5);
cA6 = appcoef(c,l,'dmey',6);
[cA1,cA2,cA3,cA4,cA5,cA6] = appcoef(c,l,[1,2,3,4,5,6]);
D = [];
D(:,6) = wrcoef('d',c,l,'dmey',6);
D(:,5) = wrcoef('d',c,l,'dmey',5);
D(:,4) = wrcoef('d',c,l,'dmey',4);
D(:,3) = wrcoef('d',c,l,'dmey',3);
D(:,2) = wrcoef('d',c,l,'dmey',2);
D(:,1) = wrcoef('d',c,l,'dmey',1);
filename = sprintf('%s_%04f.txt', 'GRACE_APROXIMATIONS', k)
csvwrite(filename,D)
end
if true
% code
end
Stephen23
Stephen23 2015년 6월 2일
편집: Stephen23 2015년 6월 2일
@Robert: the appcoef documentation shows these syntaxes:
A = appcoef(C,L,'wname',N)
A = appcoef(C,L,'wname')
A = appcoef(C,L,Lo_R,Hi_R)
A = appcoef(C,L,Lo_R,Hi_R,N)
Count the outputs: each syntax shows exactly one output. You wrote this:
[cA1,cA2,cA3,cA4,cA5,cA6] = appcoef(c,l,[1,2,3,4,5,6]);
Count the outputs: there are six of them. The error message is telling you that you have too many outputs for this function: appcoef provides only one output.
To fix this you have to call appcoef in a loop, as Walter Roberson wrote.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by