필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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

답변 (3개)

William Frane
William Frane 2014년 8월 1일
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 2014년 8월 1일
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 2014년 8월 2일
thanks for your help

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by