how to call structure data into a GUI popup menu?

2 次查看(过去 30 天)
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',???)

回答(1 个)

Image Analyst
Image Analyst 2017-5-31
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 个评论
Walter Roberson
Walter Roberson 2017-5-31
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 2017-5-31
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by