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?

 Accepted Answer

Image Analyst
Image Analyst on 11 Jan 2015

1 vote

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 Comments

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?
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.
what is the error in line43? the error now coming is:
uvec=[noise(i)uvec(1:M-1)];
|
Error: Unexpected MATLAB expression.
You need something in between there, such as a comma, space, semicolon, or * (multiplication symbol) depending on what you want to do.
Monali
Monali on 11 Jan 2015
still error is coming for variable noise1 , efa, ef? what to do now?
Stephen23
Stephen23 on 11 Jan 2015
Edited: Stephen23 on 11 Jan 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 on 11 Jan 2015
Edited: Star Strider on 11 Jan 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?
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 on 11 Jan 2015
how to preallocate arrays?
Several ways, depending on what you want:
array = zeros(rows, columns);
or
array = nan(rows, columns);
or other options.
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 on 28 Feb 2015
Thank you

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 11 Jan 2015
Edited: John D'Errico on 11 Jan 2015

1 vote

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.

Tags

Asked:

on 11 Jan 2015

Commented:

on 28 Feb 2015

Community Treasure Hunt

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

Start Hunting!