how to color circles on an image? the color should varies with the variation of the serial data

1 view (last 30 days)
i have a microcontroller connected to a force sensor and sending serial data. i'm putting these data in a matrix i need to draw circles to represent the force sensors on an image and color them the color should varies with the values of the serial data. example if the value in the matrix is 46 the color of the circle should varies from blue to red could someone help me please

Answers (3)

William Frane
William Frane on 1 Aug 2014
A simple way to do this is to plot large circular data markers on top of the image (using the hold command). Something along the lines of:
% Display image
hold on
% Iterate through all the sensors
% Get position and color for each sensor
currentColor = ConvertValueToColor(currentSensorValue);
plot(currentX, currentY, 'Marker', 'o', 'MarkerSize', 30, 'MarkerFaceColor', currentColor, 'MarkerEdgeColor', 'none');
If you normalize your sensor data such that they lie between 0 and 1, you could use something like this to vary the color:
function out = ConvertValueToColor(in) % Picks a color between blue and red
% Assumes 'in' is between 0 and 1
out = (1-in)*[0 0 1] + in*[1 0 0];

Image Analyst
Image Analyst on 1 Aug 2014
Another way is to use the rectangle() function to draw circles. Kind of crazy, but yes, rectangle() can draw circles(). I've always wondered why they just don't have a ellipse() or circle() function. But no, that would be too easy and intuitive.

marc kahwaji
marc kahwaji on 2 Aug 2014
thanks for your help

Categories

Find more on Visual Exploration in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!