Effacer les filtres
Effacer les filtres

how to call structure data into a GUI popup menu?

1 vue (au cours des 30 derniers jours)
Andrew Paulsen
Andrew Paulsen le 31 Mai 2017
Commenté : Andrew Paulsen le 31 Mai 2017
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',???)

Réponses (1)

Image Analyst
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
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.
Andrew Paulsen
Andrew Paulsen le 31 Mai 2017
Its finally starting to click. Thanks IA and Walter for all the quick responses. Just trying to push through and learn by trial and error it took me a bit to save and recall data from handle to handle. Once I got that it makes sense. My last hurdle is how to display results in a static textbox. I used a post by IA, though not getting it to work.

Connectez-vous pour commenter.

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!

Translated by