why doesn't uidropdown doesn't seem to work correctly (NOT in guide or app designer)?
27 次查看(过去 30 天)
显示 更早的评论
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.
For example, the documentation for using the uidropdown function https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-apps-created-programmatically.html#brqow8p
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 个评论
Rik
2023-8-5
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?
回答(1 个)
Suman Sahu
2023-8-22
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:
- Try re-installing or updating the appropriate graphics drivers.
- 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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!