nishat anjum khan
Member level 2
- Joined
- Aug 4, 2012
- Messages
- 44
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- 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'}))
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'}))