Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

plot two axis in same window in MATLAB

Status
Not open for further replies.

nishat anjum khan

Member level 2
Member level 2
Joined
Aug 4, 2012
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,562
hey everyone..can anyone help me in MATLAB simulation? for my project i have to receive data in MATLAB via serial communication and then have to plot it...i have to take two adc value so need to plot them in same window...since one of it is voltage and another is current so i need two axis in same window...help me please



my code:

clc;
clear all;
close all;
i=1;
count=50;
%val=55.2/8.2;
val=16/1;
data1=NaN(1,count);
data2=NaN(1,count);
s1=serial('COM1','Baudrate',57600);
fopen(s1);
hsLine= plot(data1);
hold on
hcLine= plot(data2);
while(1)

z1=fgets(s1);
z1=str2double(z1);
z1=z1*5/1024;


z2=fgets(s1);
z2=str2double(z2);
z2=z2*5/1024;


if (i<(count+1))

data1(i)=z1;
data2(i)=z2;


else
data1(1,1:count-1)=data1(1,2:count);
data1(count)=z1;

data2(1,1:count-1)=data2(1,2:count);
data2(count)=z2;

end
set(hsLine,'YData',data1);

set(hcLine,'YData',data2);
ylim([0 5]);

drawnow

i=i+1;

end
fclose(s1);
delete(instrfind({'Port'},{'COM1'}))
 

Check out "plotyy()"...

It's not as convenient/friendly to use as the regular plot function, but it might help. Alternatively, use subplot() to divide your figure window into multiple (independent) axes.
 

i am trying to use plotyy() but this isn't working properly...where i am doing wrong i don't know..can u give me any suggestion how to write it in my code?
 

i am trying to use plotyy() but this isn't working properly...where i am doing wrong i don't know..can u give me any suggestion how to write it in my code?

Why don't you write figure before the loop and hold it:

Figure;

//loop start
subplot(1,2,1); plot(x); hold on
subplot(1,2,2); plot(y); hold on
//loop end

It is much easier, I tried it before and it is working.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top