Unable to plot Graph in matlab
1 view (last 30 days)
Show older comments
Hi, I'm new to matlab. Below is the code i used to get Te,Tg, TgErr,TeErr and No of iterations. As NOI increases from 1-200 a new Te value will be generated in each iteration.I want to plot NOI vs Te, NOI vs Tg, NOI vs TeErr, NOI vs TgErr. I used plot(NOI,Te)-----but it didn't work.Please let me know the command to plot the graph.
load y
% initial conditions
pold=eye(5,5)*30;
aold=[1 -1 0 0 0]';
alpha=aold';
lambda=0.9;
t=y(1,:); Ts=t(2)-t(1); % sampling time
u=y(2,:); z=y(3,:);
MAX=size(z,2);
NOI=0; %no of iterations
for k=5:MAX-5
sold=[z(k-1) z(k-2) u(k) u(k-1) u(k-2)]';
knew=pold*sold*inv(sold'*pold*sold+lambda);
pnew=(pold-pold*sold*inv(sold'*pold*sold+1)*sold'*pold)/lambda;
anew=aold+knew*(z(k)- sold'*aold);
pold=pnew;
aold=anew;
alpha=[alpha;anew'];
%%%%calculation of time constants %%%%
Tg=-Ts/log([anew(1)+sqrt(anew(1)^2+4*anew(2))]/2);
Te=-Ts/log([anew(1)-sqrt(anew(1)^2+4*anew(2))]/2);
T =[Tg ;Te]'
%caluculating etimation erro%
TgErr=((3-Tg)/3)*100;
TeErr=((0.2-Te)/0.2)*100;
Er=[TgErr; TeErr]
NOI=NOI+1
end
4 Comments
Image Analyst
on 2 Apr 2013
That's because NOI and Te are not arrays - I think they're just single numbers - so you won't see a curve.
Answers (1)
Image Analyst
on 2 Apr 2013
Give typical values for y if you want us to try the code. If I try with rand(3,10) for y it says NOI is 1 and TE is complex.
Also if you plot Te vs. NOI, you need to make sure that they are arrays, and they are plotted after the loop (for efficiency). Like inside the loop:
Te(k) = -Ts/log([anew(1)-sqrt(anew(1)^2+4*anew(2))]/2);
Then after the loop
NOI = 1 : length(Te);
plot(NOI, Te, 'bo-', 'LineWidth', 3);
grid on;
title('Te vs. NOI', 'FontSize', 30);
xlabel('NOI', , 'FontSize', 30);
ylabel('Te', , 'FontSize', 30);
7 Comments
Walter Roberson
on 2 Apr 2013
Simulink is included with the Student Version license, but not with any of the other licenses. Image Analyst does not have a Student Version license. (I don't either.)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!