Unable to plot Graph in matlab
古いコメントを表示
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 件のコメント
Walter Roberson
2013 年 4 月 2 日
Did it produce an error message? How can you tell it did not work?
Avinash
2013 年 4 月 2 日
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.
Avinash
2013 年 4 月 2 日
回答 (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 件のコメント
Avinash
2013 年 4 月 2 日
Avinash
2013 年 4 月 2 日
Image Analyst
2013 年 4 月 2 日
編集済み: Image Analyst
2013 年 4 月 2 日
Will that open in MATLAB with load()? Or do I need Simulink (which I don't have)? I've added Simulink to the Products list above (under your question) to alert others.
Avinash
2013 年 4 月 2 日
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.)
Avinash
2013 年 4 月 2 日
カテゴリ
ヘルプ センター および File Exchange で Spline Postprocessing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!