how can i draw a circle?

6 views (last 30 days)
marc kahwaji
marc kahwaji on 5 Aug 2014
Answered: Chad Greene on 7 Aug 2014
this is my serial data code
clear all; delete(instrfind); s = serial('COM6'); instrfind set(s, 'InputBufferSize', 256); set(s, 'FlowControl', 'none'); set(s, 'BaudRate', 9600); set(s, 'Parity', 'none'); set(s, 'Timeout',1);
disp(get(s,'Name')); prop(1)=(get(s,'BaudRate')); prop(2)=(get(s,'DataBits')); prop(3)=(get(s, 'StopBit')); prop(4)=(get(s, 'InputBufferSize'));
disp(['Port Setup Done!!',num2str(prop)]); fopen(s); instrfind
stopTime = '9/24 21:53'; time = now;
i=1; j=1;
while ~isequal(datestr(now,'mm/DD HH:MM'),stopTime)
d(i,j)=fscanf(s,'%f') %reading serial data and putting them in a matrix
e=d(:,1)' %values of the first sensor
f=d(:,end)' %values of the second sensor
subplot(1,2,1);
plot(e) %plotting the values of the first sensor
grid
subplot(1,2,2);
plot(f) %plotting the values of the second sensor
grid
j=j+1; if j==3 % if the index of columns of the matrix is 3
i=i+1; %we go to a new line of the matrix we increment the index of lines
j=1; %and we put the index of columns to 1
end ;
drawnow end; fclose(s); delete(s);
clear all;
i have serial data coming from two sensors.I'm putting them in a matrix then splitting them in two matrix: e and f. e contains the values of the first sensor and f contains the values of the second sensor. i need to draw two circles, one for each sensor, and i need to color them according to the values in matrix e and f. how can i do it?
  3 Comments
marc kahwaji
marc kahwaji on 7 Aug 2014
on the same plot
marc kahwaji
marc kahwaji on 7 Aug 2014
the centers and the radius i don't care about the radius and i don't care about the position i'm receiving data between 0 and 255 when i receive 0 the two circles must be colored as blue when the value changes to 100 (for example ) the color converge towords orange ect

Sign in to comment.

Answers (2)

Geoff Hayes
Geoff Hayes on 7 Aug 2014
Edited: Geoff Hayes on 7 Aug 2014
elie - since you do not care about the centres of the circles or the radius for each (but you will when you want to draw them within your figure), you can check out the draw filled circle question which contains a couple of examples.
One uses the rectangle function which can be used to draw two circles, one within the other, as follows
figure;
hold on;
% draw a red circle with centre at (2.5,2.5) with a radius of 2.5
redColour = [1 0 0];
rectangle('Position',[0 0 5 5],'Curvature',[1 1],'EdgeColor', ...
redColour,'FaceColor', redColour)
% draw a blue circle with centre at (2.5,2.5) with a radius of 1.5
blueColour = [0 0 1];
rectangle('Position',[1 1 3 3],'Curvature',[1 1],'EdgeColor', ...
blueColour,'FaceColor', blueColour)
axis equal
Note that you will have to define your mapping from a number to a colour i.e. if received data is 0, then the colour is blue, the three element vector [0 0 1]. If the received data is 100, then the colour is orange [255 165 0]./255. (Note that this final example shows that your colour vectors must have all three values in the range of [0,1].
Try the above and see what happens!

Chad Greene
Chad Greene on 7 Aug 2014

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!