Clear Filters
Clear Filters

why doesn't uidropdown doesn't seem to work correctly (NOT in guide or app designer)?

26 views (last 30 days)
I know you are supposed to look through documentation for basic questions like this, but everything I've found is extremely confusing and unhelpful. Most of the tutorials out there also assume that if you are wanting to create graphical user interface elements that you are working in app designer, which I am not, and to my understanding has a completely different syntax for working with these, so they aren't helpful either. All I want to do is simple, have a dropdown element and access whatever is currently selected or entered, but this seems to be impossible.
says to save and run this as a .m file, but the example doesn't seem to work the way other ui objects do. It DOES is produce a figure with a dropdown menu as you would expect, but if you select a different element it does not update, the selected item just reverts back to the default value when you let go of the menu.
function updateDropDown
fig = uifigure('Position',[500 500 300 200]);
dd = uidropdown(fig, ...
'Editable','on', ...
'Items',{'Red','Green','Blue'}, ...
'ValueChangedFcn',@addItems);
end
function addItems(src,event)
val = event.Value;
if event.Edited
src.Items{end+1} = val;
end
end
for any other uielement, I can simply access object.Value to access whatever that element has been set at, and if the selection changes that variable changes, but it seems to be impossible to change uidropdown's object.Value.
I gather the answer has to do with callbacks somehow, but I cannot find a good tutorial or explanation for these, they all seem to assume you are using app designer. for example:
why are some callbacks written as @(src, event) callback (src, event) whereas others are
@callback(src, event)
what is src and what is event? these are never previously defined variables, they seem to just be something you have to add in for syntax reasons, but what actually are they? The syntax for using callbacks also seem to be inconsistent. the uicontrol function seems to be very different from any of the others.
Is there a more detailed documentation for using callbacks on ui elements OUTSIDE of app editor for this other than the official one that someone could point me to? because that does not do a good job explaining anything. And why can't I make even a simple dropdown menu that actually lets me interact?
  5 Comments
Rik
Rik on 5 Aug 2023
I'm on mobile so searching the documentation is harder (as is testing it), but is there a reason you're using ValueChangedFcn instead of Callback? And have you tried setting breakpoints in your callback function to see what is happening with the variables?
Andrew Morris
Andrew Morris on 6 Aug 2023
I've tried the simplest code possible:
fig = uifigure;
dd = uidropdown('Items',{'option1', 'option2', 'option3'});
it will still not let me click on anything other than the default option, even without any callback.
dd.Value is always "option1"
I think this is relevent. The following loads on the terminal when MATLAB is started:
MATLAB is selecting SOFTWARE OPENGL rendering.
MESA-LOADER: failed to open radeonsi: /usr/lib/dri/radeonsi_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
failed to load driver: radeonsi
MESA-LOADER: failed to open zink: /usr/lib/dri/zink_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
failed to load driver: zink
MESA-LOADER: failed to open kms_swrast: /usr/lib/dri/kms_swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
failed to load driver: kms_swrast
MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
failed to load swrast driver.
I will try this again on Windows and see if i can get it to work. This is not not the first time I've had a problem with OpenGL and MATLAB running on Linux.

Sign in to comment.

Answers (1)

Suman Sahu
Suman Sahu on 22 Aug 2023
Hi Andrew,
I have tried running your code on my machine(Windows) and there does not seem to be any issue with the code. I looked at your comments, you are working on a Linux machine and the issue is apparently with your graphics drivers. Here are some troubleshooting steps that you can follow to resolve your issue:
  1. Try re-installing or updating the appropriate graphics drivers.
  2. OpenGL configuration: Try to run MATLAB with hardware OpenGL rendering if software OpenGL is being used and try software OpenGL rendering if hardware OpenGL is being used.
You can check the current rendering implementation using the following function in MATLAB command window:
Info = rendererinfo(gca)
To start MATLAB session with hardware OpenGL use following command in your system’s command prompt or terminal:
matlab -nosoftwareopengl
To start MATLAB session with software OpenGL use:
matlab -softwareopengl

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!