gamma1(i)=gamma(i-1)*lambda*epf(i-1)/epf(i)
here the error showing is that
" Invalid syntax at'='. Possibly a ),},or ] is missing"
rectify what is the mistake here and how to correct it?

 Respuesta aceptada

Image Analyst
Image Analyst el 11 de En. de 2015

1 voto

There is nothing wrong with that code. Please tell us the entire error message, not a small part of it like you did. What you showed is not a MATLAB error message. How do I know? Well it doesn't have line numbers or function names for one thing. Also tell us the value of i when it errors. With syntax errors, it's possible that the error actually starts on the line before what it says.

12 comentarios

Monali
Monali el 11 de En. de 2015
gamma1(i)=gamma(i-1)*lambda*epf(i-1)/epf(i);
|
Error: The expression to the left of the equals sign is not a valid target for an assignment.
The code is:
M=25; N=1000; Delay=3; lambda=1;
noise=randn(N,1);
noise1=filter([zeros(1,Delay)],1,noise);
[Num,Den]=butter(10,0.5);
noise1=filter(Num,Den,noise);
noise1=noise1/std(noise1)*0.5;
weights=zeros(M,length(noise1)+1);
d=signal+noise1;
%INITIALIZATION
epsilon=0.00001;
w=zeros(M,N);
uvec=zeros(1,M);
e=zeros(N,1);
wf(1:M,1)=0;
wb(1:M,1)=0;
w(1:M,1)=0;
phi(1:M,1)=0;
gamma(1)=1;
epb(1:M,1)=epsilon;
epf(1:M,1)=epsilon;
%Filtering Algorithm
for i=2:length(noise1)
%Forward A Priori Prediction Error
efa(i)=noise(i)-uvec*wf(:,i-1);
%Forward A Posterior Prediction Error
ef(i)=efa(i)*gamma(i-1);
%MWLS Forward Error
epf(i)=lambda*epf(i-1)+efa(i)*(ef(i))';
%Forward Weight Update
wf(:,i)=wf(:,i-1)+phi(:,i-1)*ef(i);
phi1(:,i)=[0;phi(:,i-1)+efa(i)'/(lambda*epf(i-1))*[1;wf(:,i-1)];
%M+1 Conversion Factor
gamma1(i)= gamma(i-1)*lambda*epf(i-1)/epf(i);
%Backward A Priori Prediction Error
eba(i)=lambda*epb(i-1)*phi1(M+1,i);
gammainv=1/gamma1(i)-phi1(M+1,i)*eba(i);
gamma(i)=1/gammainv;
eb(i)=eba(i)*gamma(i);
epb(i)=lambda*epb(i-1)+eb(i)*eba(i)';
newvec=phi1(:,i)-phi1(M+1,i)*[-wb(:,i-1);1];
phi(:,i)=newvec(1:M);
wb(:,i)=wb(:,i-1)+phi(:,1)*eb(i);
uvec=[noise(i)uvec(1:M-1)];
ea(i)=d(i)-uvec*w(:,i-1);
e(i)=ea(i)*gamma(i);
w(:,1)=w(:,i-1)+e(i)*phi(:,1);
end
The error comes at line 36.. how to correct it?
Image Analyst
Image Analyst el 11 de En. de 2015
Like I said, look above. Look at this line:
phi1(:,i)=[0;phi(:,i-1)+efa(i)'/(lambda*epf(i-1))*[1;wf(:,i-1)];
Why do you have two left brackets but only one right bracket. I don't know what you want there so it's up to you to fix it. But definitely , you need the same number of left and right brackets and left and right parentheses.
Monali
Monali el 11 de En. de 2015
what is the error in line43? the error now coming is:
uvec=[noise(i)uvec(1:M-1)];
|
Error: Unexpected MATLAB expression.
Image Analyst
Image Analyst el 11 de En. de 2015
You need something in between there, such as a comma, space, semicolon, or * (multiplication symbol) depending on what you want to do.
Monali
Monali el 11 de En. de 2015
still error is coming for variable noise1 , efa, ef? what to do now?
Stephen23
Stephen23 el 11 de En. de 2015
Editada: Stephen23 el 11 de En. de 2015
That is easy: read the error message, understand the problem, and fix it. Learn to debug code.
If you want us to help you with this, then you need to give us more information (we cannot read minds or computer screens on other continents). At a minimum you need to tell us the entire error message and show the code that you are running.
Monali
Monali el 11 de En. de 2015
Editada: Star Strider el 11 de En. de 2015
M=25; N=1000; Delay=3; lambda=1;
n = (1:N);
signal=sin(0.075*pi*n);
noise=randn(N,1);
noise1=filter([zeros(1,Delay)],1,noise);
[Num,Den]=butter(10,0.5);
noise1=filter(Num,Den,noise);
noise1=noise1/std(noise1)*0.5;
weights=zeros(M,length(noise1)+1);
d=signal+noise1;
%INITIALIZATION
epsilon=0.00001;
w=zeros(M,N);
uvec=zeros(1,M);
e=zeros(N,1);
wf(1:M,1)=0;
wb(1:M,1)=0;
w(1:M,1)=0;
phi(1:M,1)=0;
gamma(1)=1;
epb(1:M,1)=epsilon;
epf(1:M,1)=epsilon;
%Filtering Algorithm
for i=2:length(noise1)
%Forward A Priori Prediction Error
efa(i) = zeros(1,100000);
efa(i)=noise(i)-uvec*wf(:,i-1);
%Forward A Posterior Prediction Error
ef(i)=efa(i)*gamma(i-1);
%MWLS Forward Error
epf(i)=lambda*epf(i-1)+efa(i)*(ef(i))';
%Forward Weight Update
wf(:,i)=wf(:,i-1)+phi(:,i-1)*ef(i);
phi1(:,i)=[0;phi(:,i-1)+efa(i)]/(lambda*epf(i-1))*[1;wf(:,i-1)];
%M+1 Conversion Factor
gamma1(i)= gamma(i-1)*lambda*epf(i-1)/epf(i);
%Backward A Priori Prediction Error
eba(i)=lambda*epb(i-1)*phi1(M+1,i);
gammainv=1/gamma1(i)-phi1(M+1,i)*eba(i);
gamma(i)=1/gammainv;
eb(i)=eba(i)*gamma(i);
epb(i)=lambda*epb(i-1)+eb(i)*eba(i)';
newvec=phi1(:,i)-phi1(M+1,i)*[-wb(:,i-1);1];
phi(:,i)=newvec(1:M);
wb(:,i)=wb(:,i-1)+phi(:,1)*eb(i);
uvec=[noise(i),uvec(1:M-1)];
ea(i)=d(i)-uvec*w(:,i-1);
e(i)=ea(i)*gamma(i);
w(:,1)=w(:,i-1)+e(i)*phi(:,1);
end
The error message is:
Error using +
Matrix dimensions must agree.
What to do now?
Star Strider
Star Strider el 11 de En. de 2015
Check the sizes of the terms in the line that is throwing the error.
(And please use the [{}Code] button next time you post a block of code.)
Monali
Monali el 11 de En. de 2015
how to preallocate arrays?
Star Strider
Star Strider el 11 de En. de 2015
Several ways, depending on what you want:
array = zeros(rows, columns);
or
array = nan(rows, columns);
or other options.
Image Analyst
Image Analyst el 11 de En. de 2015
Wow, third error that you're trying to fix via back and forth forum messages. It's really time for you to read this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ so that you can solve problems yourself much, much faster than asking us.
Monali
Monali el 28 de Feb. de 2015
Thank you

Iniciar sesión para comentar.

Más respuestas (1)

John D'Errico
John D'Errico el 11 de En. de 2015
Editada: John D'Errico el 11 de En. de 2015

1 voto

There is absolutely NOTHING wrong with THAT line of code. However...
This kind of error usually indicates you might find an error in a previous line. This is my guess. You have gotten the parser, let me say, confused. It thinks it sees an error in that line, but you are missing a paren or bracket in one of the lines that came before. So when that bracket was missing, it thinks the line was continued onto the next line or so. Then it sees something it cannot understand in context of a continued line, so it gets upset. But it reports an error on the wrong line!
Yes, I know this is sort of a feature. Hey, some would call it a bug. Once you learn what is happening when you see an error like that, you know what to look for, and WHERE to look.

Etiquetas

Preguntada:

el 11 de En. de 2015

Comentada:

el 28 de Feb. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by