MATLAB Answers

Guide handing objects to functions

조회 수: 1(최근 30일)
Robert Worm
Robert Worm 17 Aug 2018
댓글: Robert Worm 17 Aug 2018
Using Guide I have two radiobuttons. When pushing one the other has to be unchecked. So far this is my solution:
function distButton_Callback(hObject, eventdata, handles)
checkThis = get(handles.distButton, 'Value');
checkThat = get(handles.fftButton, 'Value');
if checkThis == checkThat
set(handles.fftButton, 'Value', ~checkThis);
end
Since there are four button pairs a function would save a couple of lines.
Calling the function:
checkThis('distButton', 'fftButton', handles);
However combining handles. with a string does not seem to convert this to 'distButton'
> Reference to non-existent field 'this'.
function checkThis(this, that, handles)
checkThis = get(handles.this, 'Value');
checkThat = get(handles.that, 'Value');
if checkThis == checkThat
set(handles.that, 'Value', ~checkThis);
end
It's probably a simple matter of syntax..
  댓글 수: 2
Robert Worm
Robert Worm 17 Aug 2018
Since this is my first time working with guide, I was simply not aware of that. Thanks for the advice.

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

채택된 답변

ES
ES 17 Aug 2018
function checkThis(this, that, handles)
checkThis = get(eval(['handles.', this]), 'Value');
checkThat = get(eval(['handles.', that]), 'Value');
if checkThis == checkThat
set(eval(['handles.', that]), 'Value', ~checkThis);
end
  댓글 수: 3
Robert Worm
Robert Worm 17 Aug 2018
Much appreciated. I will take this into account.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by