필터 지우기
필터 지우기

Apart from main program, executing function continuously GUI matlab.

조회 수: 10 (최근 30일)
Carlos
Carlos 2017년 2월 23일
댓글: Walter Roberson 2017년 6월 9일
Dear experts,
this is Carlos. Now, I'm programming a GUI in Matlab.
In this GUI, I have some buttons and static texts. Particularly, I would like to change the text of a static box continuously, i.e., regardless the changes made in the main program.
Concretely, this static box takes the values from other hardware. The values obtained from this hardware have to be shown constantly. Simultaneously this static box shows the values from the hardware, I would like to press other buttons and carry out other functions.
The concept I look for, probably, is a kind of parallel programming. However, I think an easier solution should have.
Thank you in advance.
Carlos.
  댓글 수: 7
Geoff Hayes
Geoff Hayes 2017년 2월 24일
Carlos - how is save_pos called? Is it from within your GUI or from the command line? Does it have a timer that periodically queries your device for the distance (or some other information)?
Walter Roberson
Walter Roberson 2017년 2월 24일
Carlos, you did not answer the question about what kind of hardware you are interfacing? I have most of the toolboxes and I checked all of the get() functions but get() does not fetch from hardware for any of the ones I have.
The reason that it is important is that there may be other ways of fetching your data asynchronously.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2017년 2월 23일
편집: Jan 2017년 3월 8일
You can use a timer to update the GUI. Store the handle of the GUI object to be affected in the timer's UserData, such that it is available in the TimerFcn.
function myGUI
FigH = figure;
TextH = uicontrol('Style', 'Text', 'Position', [10, 10, 200, 24]);
TimerH = timer('UserData', TextH, 'TimerFcn', @myTimerFcn, 'Period', 1, ...
'ExecutionMode', 'fixedRate');
drawnow;
start(TimerH);
end
function myTimerFcn(TimerH, EventData)
TextH = get(TimerH, 'UserData');
set(TextH, 'String', datestr(now, 0));
drawnow; % Thanks Walter
end
Store the handle of the timer in the figure's UserData or ApplicationData (e.g. by handles.timerH = timer(...), such that it can be deleted in the CloseRequestFcn of the figure automatically.
  댓글 수: 6
Evrim Yilmaz
Evrim Yilmaz 2017년 6월 8일
Hi Jan, I have tried to compile this code in my matlab gui which is already working. But I get an error for "function mygui" line. Do you know why? Thanks
Walter Roberson
Walter Roberson 2017년 6월 9일
You need to save that code to myGUI.m

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by