I have serial connection. I would like to have a green circle blinking in the screen while connection is on and a red circle while connection is off.
do i need to use axes for that?

 Akzeptierte Antwort

Baltam
Baltam am 19 Apr. 2016

0 Stimmen

Personally I would do it with axes yes. Below an example of green and red circle depending on parameter x.
x = [0 1];
for i =1:numel(x)
rectangle('Position', [0.0 0.0 1 1], 'Curvature', [1 1], 'FaceColor', [x(i) 1-x(i) 0]) % with x = parameter
ax = gca;
% remove tick labels
set(ax,'XTick',[]),set(ax,'YTick',[])
% make lines of the axes white --> invisible on white background
set(ax,'XColor',[1,1,1]) , set(ax,'YColor',[1,1,1])
% make axes square to get round circle
axis square
pause(0.5)
end
Kind regards,
Baltam

4 Kommentare

Daniel
Daniel am 20 Apr. 2016
what is x? how do i link this to axis?
Baltam
Baltam am 20 Apr. 2016
x is your variable. In your case wether the connection is on or off. You should make axes in your GUI and implement code in your GUI code that checks if the connection is on and then update the axes by updating the variable 'x' first.
Daniel
Daniel am 21 Apr. 2016
thanks. it works. follow up question: what if i want to make it blink? i know i can make it appear and disappear, but i want this operation to happen while other code is running. is this an interrupt situation?
Baltam
Baltam am 21 Apr. 2016
Bearbeitet: Baltam am 21 Apr. 2016
I believe you need something like this and adjust the function to make it change the color of the circle to white. I never used it before so good luck. I also read if you are doing heavy caculations the timer will not do its function in the background but it will do its task whenever some time is available.
t = timer;
t.ExecutionMode = 'fixedRate';
t.Period = 1;
t.TimerFcn = @(~,~)disp('1s elapsed');
start(t)
Good luck,
Baltam

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 19 Apr. 2016

Bearbeitet:

am 21 Apr. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by