how to call structure data into a GUI popup menu?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a pushbutton programmed to pull in data (3X1 struct with 43 fields). I then want to display the data from all rows of one field in a popup menu. I am struggling to get this to work. Do I need to convert it to a string first? How? Then how do I call that back into the popup... set(hObject,'String',??)?
popupmenu1_CreateFcn(hObject, eventdata, handles)
handle to lat1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject,'String',???)
0 commentaires
Réponses (1)
Image Analyst
le 31 Mai 2017
Don't do anything with any CreateFcn() functions. Put the code to load the strings into the popup in your pushbutton callback that reads in your data. Let's say that str43 is the name of your structure with 43 fields in it. And let's say the field called "field1" is the field that contains the data. And let's say you want to get that field from the second structure in your 3x1 structure array. You can get it by doing
field1 = str43(2).field1;
Now, you need to convert the rows of field1 into strings. How to do that depends on what kind of variable field1 is. If field1 is a cell array of strings, then you can do
handles.popupmenu1.String = field1;
If it's a row or column vector of floating point numbers, then you can do
for row = 1 : size(field1)
popupStrings{k} = sprintf('%f', field1(k)); % Convert number to string.
end
% Send cell array to the popup comtrol:
handles.popupmenu1.String = popupStrings;
If field1 is some other kind of variable, then you're going to have to figure out how you want it to appear in your popup list and do something to make the cell array of strings.
5 commentaires
Walter Roberson
le 31 Mai 2017
Side note: to get more than one result from a listbox, you need to set its Max parameter to greater than 1.
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!