MATLAB GUI; Hello, I have a problem with a code in MATLAB. I hope you can help m
ID: 3736567 • Letter: M
Question
MATLAB GUI;
Hello, I have a problem with a code in MATLAB. I hope you can help me out. The question is how can I called the specific user selection from a button panel selection function into a push button function. Here is the code that I have from the button panel selection function;
% --- Executes when selected object is changed in BoundaryConditionPanel.
function BoundaryConditionPanel_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in BoundaryConditionPanel
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load('Properties.mat')
switch get(eventdata.NewValue, 'Tag')
case 'Cantilever_Toggle'
Properties.B = 1;
case 'SimplySupported_Toggle'
Properties.B = 2;
case 'FixedFixed_Toggle'
Properties.B = 3;
case 'CantileverRollerSupport_Toggle'
Properties.B = 4;
end
save('Properties.mat','Properties');
Explanation / Answer
you have two push button callbacks as follows
where each defines local variables humanProtein and mouseProtein respectively. Your checkbox callbox is defined as
The first line of code (after the signature) references two undefined variables, the mouseProtein and humnaProtein. This is probably the source of your error: your code is referencing variables that have been defined locally in other callbacks. When using GUIDE to design your GUI, if you create a local variable in one callback function that you want to reference in another callback function, you need to save this variables as user-defined data within the handles structure. To do this, change your pushbutton callbacks as follows
In the above, we save each local variables as a field within handles and then save the updated structure using guidata. Now, in your checkbox callback, you would do
In the above, we check to see if the handles structure has the two fields that we are interested in using isfield. If both exist, then we get each variable by accessing the desired field within that structure.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.