what is this error: Unexpected MATLAB expression?? andhow can i fix it???

Dear Sir,
I am looking to make radar system by using the chirp generator (to generate chirp signal as sawtooth signal from low to high frequency). I will use the operational amplifier as part of my research work to make amplification to sawtooth signal so I made search in the internet to learn how I can make operational amplifier by the Matlab. After long time, I found something can help me in how i can make inverting amplifier by Matlab circuit where it is nearest to the operational amplifier that I will use in my research work. After I made run to this program by the matlab that I found there is error " Unexpected MATLAB expression". I would like to know "Where is the error in this program to fix it and making changing in some commands in this program to use it in my research work??"
I would like to help me as soon as possible...
-------------------------------------------------------------------------------------
This is the matlab code:
R1=10e3; % resistance, ohms
R2=20e3; % resistance, ohms
R3=20e3; % resistance, ohms
R4=20e3; % resistance, ohms
R5=20e3; % resistance, ohms
% op amp parameter
vsat=15; % saturation voltage,V
% source parameters
M=3; % amplitude, V
f=1000; % frequency, Hz
w=2*pi*f; % frequency, rad/s
theta=(pi/180)*45; % phase angle, rad
tf=2/f; % final time
N=200; % number of increments
t=0:tf/N:tf; % time, s
vs = M*cos(w*t+theta); % input voltage
for k=1:length(vs)
Y=[ 1/R2, 1/R2 + 1/R3 + 1/R4; % nodal admittance matrix
0, -1/R3];
J=[-vs(k)/R1 0 ]; % input current vector
V=J/Y; % node voltage vector
vo(k)=V(2); % record the output voltage
if (vo(k)>vsat) vo(k)=vsat; % check for saturation
elseif (vo(k)<-vsat) vo(k)=-vsat;
end
end
plot(t, vo, t, vs) % plot the transfer characteristic
axis([0 tf -20 20])
xlabel('time, s')
ylabel('vo(t), V')

 Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 2 Aug. 2012

0 Stimmen

If you run that, what line does the error occur on? You are likely missing a ')', ']' or '}' or similar.

12 Kommentare

Dear Sean,
Thank you very much on your interesting....
The error is from line 23 to 25:
line 23: vo(k)=V(2); % record the output voltage
line 25: elseif (vo(k)<-vsat) vo(k)=-vsat;
Line 25 is not valid. If you would like to have the conditional be vo(k)<-vsat and if this is the case then set vo(k) equal to vsat6 you will need a comma, semicolon, or new line:
elseif (vo(k)<-vsat), vo(k)=-vsat;
Note, you could replace this if statement with
vo(k) = max(vo(k),-vsat)
Dear Sir,
Thank you very much on your interesting...
I made the steps that you said but I have the same problem so I would like to make sure that I fix the mistakes such you want:
This is mat. file after changing:
for k=1:length(vs)
Y=[ 1/R2, 1/R2 + 1/R3 + 1/R4; % nodal admittance matrix
0, -1/R3];
J=[-vs(k)/R1 0 ]; % input current vector
V=J/Y; % node voltage vector
vo(k)=v(2); % record the output voltage
if (vo(k)>vsat), vo(k)=vsat; % check for saturation
vo(k) = max(vo(k),-vsat)
%elseif (vo(k)<-vsat), vo(k)=vsat6;
end
end
Thank you very much
No. You would have to remove both components of the if-statement in order to use min/max to perform the saturation.
vo(k) = max(vo(k),-vsat);
vo(k) = min(vo(k),vsat);
Now remove all components of the if-statement.
doc max
doc min
for more information.
Dear Sean,
I removed both the if-statment and I am still have the same error:
This is mat. file after changing:
for k=1:length(vs)
Y=[ 1/R2, 1/R2 + 1/R3 + 1/R4; % nodal admittance matrix
0, -1/R3];
J=[-vs(k)/R1 0 ]; % input current vector
V=J/Y; % node voltage vector
vo(k)=v(2); % record the output voltage
%if (vo(k)>vsat), vo(k)=vsat; % check for saturation
vo(k) = min(vo(k),vsat);
vo(k) = max(vo(k),-vsat)
%elseif (vo(k)<-vsat), vo(k)=vsat6;
end
Thank you very much
dbstop if error
Will stop on the line that throws the error. Then run that line piecemeal to find out what part is broken.
Dear Sean,
I made such as your told me and I found the error in this line:
vo(k)=V(2);
I do not know "What is the probelm here so i would like to help me to fix this error??"
Thank you very much
Does the above expression work?
Star Strider
Star Strider am 3 Aug. 2012
Bearbeitet: Star Strider am 3 Aug. 2012
I copy-pasted the posted code to a test file and ran it. It ran without an error.
Dear Sean,
Thank you very much on your helping....
With your helping, I can fix the problem...
Thank you very much
Have Great and Fantastic Day
I had no prolems when I cut and pasted your code.
What version of MATLAB do you ave?
Thank you very much, Sean...
I have Matlab Version 2008

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by