Transfer data through callback function up to uibuttongroup
Mostrar comentarios más antiguos
My GUI is built with the following code:
function test_function
fig_conf = figure('Visible', 'off', 'Position', [50, 200, 600, 600]);
set(fig_conf, 'ToolBar', 'none');
group1 = uibuttongroup('Title', '1. Group','FontSize', 8, 'FontName', 'Courier',...
'Position', [0.05 0.8 0.35 0.175], 'SelectionChangedFcn',@bselection);
test = get(hp_tec,'UserData')
opt1 = uicontrol(group1, 'Style', 'radiobutton', 'String', 'Option 1', 'FontName', 'Courier',...
'Position', [10 65 75 25]);
opt1 = uicontrol(group1, 'Style', 'radiobutton', 'String', 'Option 2', 'FontName', 'Courier',...
'Position', [10 45 75 25]);
opt1 = uicontrol(group1, 'Style', 'radiobutton', 'String', 'Option 3', 'FontName', 'Courier',...
'Position', [10 25 100 25]);
set(dmeldacs, 'Enable', 'off');
opt4 = uicontrol(group1, 'Style', 'radiobutton', 'String', 'Option 4', 'FontName', 'Courier',...
'Position', [10 5 75 25]);
end
Where the callback function that I've used is this:
function bselection(hObject,eventdata)
display(['Previous: ' eventdata.OldValue.String]);
display(['Current: ' eventdata.NewValue.String]);
display('------------------');
set(hObject,'UserData',eventdata.NewValue.String)
end
My problem is related to read the data contained in group1.UserData, i.e. the variable 'test' in fourth line doesn't appear in Workspace variables list when the option selected changes between the different radio buttons. I don't understand where I'm wronging.
2 comentarios
Adam
el 3 de Ag. de 2016
'test' has function scope and your function ends after you set up all your uicontrols so all the variables contained within it go out of scope. So when you first trigger your callback you will just be in the base workspace and your callback doesn't cause anything to happen anywhere else, just setting the 'UserData' property of your uicontrol.
I don't understand what this line is doing though:
test = get(hp_tec,'UserData')
hp_tec does not seem to exist anywhere in that scope so I would assume this would crash.
Apart from that most things in Matlab are passed by value so a variable that refers to e.g. the 'UserData' of a control will pick up the value of that control once, when called, it will not update itself when the property it asked for changes.
Giuseppe Battista
el 3 de Ag. de 2016
Respuestas (0)
Categorías
Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!