Using an array to populate a drop-down list
Mostrar comentarios más antiguos
Essentially, I'd like to be able to fill a drop-down list with an array; essentially, the idea is that the user will select which variables are known to them, the program will output what variables can be solved for, and the user can select one of those variables. I've got most of it working; however, I am hitting an issue with getting the list to successfully populate. I've pasted the relevant parts of my code here:
function pushbutton2_Callback(hObject, eventdata, handles)
global InitialPositionUI
global FinalPositionUI
global ChangeInPositionUI
tally = 1;
if InitialPositionUI == 1
if FinalPositionUI == 1
s{tally} = {'Change in Position'};
tally = tally + 1;
end
end
choosedialog(s)
function choice = choosedialog(s)
d = dialog('Position',[300 300 250 150],'Name','Select One');
txt = uicontrol('Parent',d,...
'Style','text',...
'Position',[20 80 210 40],...
'String','Choose a variable');
popup = uicontrol('Parent',d,...
'Style','popup',...
'Position',[75 70 100 25],...
'String',{s},...
'Callback',@popup_callback);
btn = uicontrol('Parent',d,...
'Position',[89 20 70 25],...
'String','Close',...
'Callback','delete(gcf)');
choice = 'placeholder';
% Wait for d to close before running to completion
uiwait(d);
function popup_callback(popup,callbackdata)
idx = popup.Value;
popup_items = popup.String;
choice = char(popup_items(idx,:));
So the issue seems to be in my efforts to import the 's' array to the drop-down menu as choices. Is there any easier way to do this? As it stands, I'm getting an error that says, "Cell array of strings may only contain string and numeric matrices".
1 comentario
Image Analyst
el 16 de Sept. de 2015
Editada: Image Analyst
el 16 de Sept. de 2015
What issue are you having? Does the popup contain anything at all? What is the value of "s" before you call choosedialog(s)? Paste it back here so we can see it. And what is the purpose of tally? All you do is potentially increment it, and then never use it again.
Respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!