Control ONE Pop Up Menu depending on ANOTHER Pop Up Menu

Hi everyone!
Hope all is well.
I have two pop-up menus named Popup 11 and Popup 16 with different selections on each pop-up menus. I tried the following code where If i select 1 in Popup 11, it should automatically select another in Popup16.
However, I got the following error:
'Unrecognized method, property, or field 'value' for class 'matlab.ui.control.UIControl'.
The following is my code:
function popup11_Callback(hObject, eventdata, handles)
if isequal(hObject.value, 1)
handles.popup16.value = 1;
end

Antworten (1)

Geoff Hayes
Geoff Hayes am 4 Apr. 2020
Miss B - which version of MATLAB are you using? On older versions, you may need to do something like
if get(hObject, 'Value') == 1
set(handles.popup16, 'Value', 1);
end
Else put a breakpoint at the first line of this function, launch your GUI and select an item in your popup11. When the debugger pauses at this line, check to see what the fields are for hObject. Does a value field exist?

9 Kommentare

Miss B
Miss B am 4 Apr. 2020
Bearbeitet: Miss B am 4 Apr. 2020
Thank you for your response Geoff!
Much Appreciated!
I am using Matlab R2020a.
Will the code be ok for the mentioned version above?
I tried the code you've given. The same error pops up.
'Unrecognized method, property, or field 'value' for class 'matlab.ui.control.UIControl'.
No, my way won't work for later versions. Which fields do you see for your hObject? Perhaps you need to capitalize Value as
function popup11_Callback(hObject, eventdata, handles)
if isequal(hObject.Value, 1)
handles.popup16.Value = 1;
end
Miss B
Miss B am 4 Apr. 2020
Bearbeitet: Miss B am 5 Apr. 2020
I'm not too sure what my hObject is here - I kinda just experimented with the codes.
In Popupmenu11 - Once I select a specified 'Option' it should automatically select the other 'Option' in Popupmenu16 freezing the other selections...I apologise if i'm confusing you :(
I tried capitalising 'Value' but still the same error.
Unrecognized function or variable 'MK6002'.
Error in module_grade>popup11_Callback (line 2034)
if isequal(hObject.Value, MK6002)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in module_grade (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)module_grade('popup11_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
if isequal(hObject.Value, MK6002)
handles.popup16.Value = 30;
end
You're getting a different error here...but it looks like using Value works. The new error message is telling you that you are trying to use a variable that doesn't exist because you have coded MK6002 as a variable and not as a string 'MK6002'. But hObject.Value is probably an integer so comparing the two in this way won't work. To determine what it is do
function popup11_Callback(hObject, eventdata, handles)
popupValue = hObject.Value
% if isequal(hObject.Value, MK6002)
% handles.popup16.Value = 30;
% end
and you should see - in the command window - what **popupValue is: an integer or string. If an integer, then it will represent an index into the array of strings that populate your popup. You'll probably need to do something like
function popup11_Callback(hObject, eventdata, handles)
popupValue = hObject.Value;
popupStrings = hObject.String;
selectionString = popupStrings{popupValue}; % I'm assuming a cell array so use {}
if strcmp(selectionString, 'MK6002')
% do something
end
Thank you for the detailed help above.
But that didn't quite help either...
My Error below:
Unrecognized function or variable 'strmcp'.
Error in module_grade>popup11_Callback (line 2038)
if strmcp(selectionString, 'MK6002')
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in module_grade (line 42)
gui_mainfcn(gui_State, varargin{:});
Error inmatlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)module_grade('popup11_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
My Code Below:
popupValue = hObject.Value;
popupStrings = hObject.String;
selectionString = popupStrings{popupValue};
if strmcp(selectionString, 'MK6002')
handles.popup16.Value = 30;
end
strcmp not strmcp
Thank you for that!
I am so sorry about this...but i got the following message.
Warning: 'popupmenu' control requires that 'Value' be an integer within Character vector range
Control will not be rendered until all of its parameter values are valid
handles.popup16.Value = 30;
That is a request for entry #30 in popup16 to become the active entry.
What if there are fewer than 30 entries in popup16 at the time you make the request?
Setting the Value of a popup does not change the text displayed by a popup: it changes which of the text items are to be displayed.
If you wanted to change the text of the current selection to '-30-' then:
curpos = handles.popup16.Value;
handles.popup16.String{curpos} = '-30-';
You are a life saver!!!!
Thank you so so so much!
I appreciate it so much!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Apr. 2020

Bearbeitet:

am 5 Apr. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by