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 Kommentare

Walter Roberson
Walter Roberson am 2 Apr. 2013
Did it produce an error message? How can you tell it did not work?
Avinash
Avinash am 2 Apr. 2013
when i took plot(NOI,Te) it is taking NOI values on x axis and Te values on Y axis.... i could't find any graph.
Image Analyst
Image Analyst am 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.
Avinash
Avinash am 2 Apr. 2013
Ok..... I don't know how to code arrays in matlab.I will now try writing arrays. Thank you very much Image Analyst.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 2 Apr. 2013

0 Stimmen

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 Kommentare

Avinash
Avinash am 2 Apr. 2013
Y is output of simulink. How can i upload my simulink ckt here?
Avinash
Avinash am 2 Apr. 2013
I uploaded my simulink in the below link:
Image Analyst
Image Analyst am 2 Apr. 2013
Bearbeitet: Image Analyst am 2 Apr. 2013
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
Avinash am 2 Apr. 2013
isn't simulink in built in matlab? do we need to install seperately?
Walter Roberson
Walter Roberson am 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.)
Avinash
Avinash am 2 Apr. 2013
Ok.....Thanks for your time. I figured it out

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Gefragt:

am 2 Apr. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by