Unable to plot Graph in matlab
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2013-4-2
That's because NOI and Te are not arrays - I think they're just single numbers - so you won't see a curve.
回答(1 个)
Image Analyst
2013-4-2
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 个评论
Walter Roberson
2013-4-2
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.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!