GUI's and Popup Menu List Creation From Stored Cell Array of Strings.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Is there a way to populate a popup menu list from a cell array of strings that are already stored?
For example: I have a GUI which locates a specific data file based on the value of a editable text field upon execution of push button 1. This file is then read in, manipulated and stored as a data table and a cell array of column header strings. After the data has been loaded, the x-axis and y-axis variables to be plotted should be selected from a drop down list which contains the column headers for the specified file. Then upon execution of push button 2 the selected data is to be plotted. Defining the cell array of strings is easy, but I am not clear on how to use this to define the popup menu list.
Disclaimer: I am new to the whole Matlab GUI thing and I realize that this is proabaly trivial, but I would really appreciate any and all help. That being said, I did read several other threads that sounded promising but I have had no luck in implementing what was suggested. My code is shown below.
varliststr is the cell array of column headers
function varargout = CC510_GUI(varargin)
%CC510_GUI M-file for CC510_GUI.fig
% CC510_GUI, by itself, creates a new CC510_GUI or raises the existing
% singleton*.
%
% H = CC510_GUI returns the handle to a new CC510_GUI or the handle to
% the existing singleton*.
%
% CC510_GUI('Property','Value',...) creates a new CC510_GUI using the
% given property value pairs. Unrecognized properties are passed via
% varargin to CC510_GUI_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% CC510_GUI('CALLBACK') and CC510_GUI('CALLBACK',hObject,...) call the
% local function named CALLBACK in CC510_GUI.M with the given input
% arguments.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help CC510_GUI
% Last Modified by GUIDE v2.5 13-Jun-2012 15:59:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @CC510_GUI_OpeningFcn, ...
'gui_OutputFcn', @CC510_GUI_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before CC510_GUI is made visible.
function CC510_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for CC510_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes CC510_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = CC510_GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function TESTID_Callback(hObject, eventdata, handles)
% hObject handle to TESTID (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of TESTID as text
% str2double(get(hObject,'String')) returns contents of TESTID as a double
input=get(hObject,'String');
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function TESTID_CreateFcn(hObject, eventdata, handles)
% hObject handle to TESTID (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in FindData.
function FindData_Callback(hObject, eventdata, handles)
% hObject handle to FindData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
format long
MID=get(handles.TESTID,'String');
message=horzcat('STATUS: Finding Data for Test ID ',MID,'...');
disp(message)
file1='R:\Consulting\SimCom\Matlab\Mustang_Test_Pts-SimCom.xls';
[data1 text1]=xlsread(file1);
[m1,n1]=size(text1);
for i=1:m1
if strcmp(text1(i,1),MID)==1
imid=i;
break
end
end
dir21='R:\Consulting\SimCom\Customer Furnished Data\Cessna Data Package\Cessna Data Package\';
dir22='T00247_CE510_flt_test_data_20120314164444\';
dir2=horzcat(dir21,dir22);
file21=text1(imid,17);
file2=strcat(dir2,file21);
[data2,text2]=xlsread(file2{1});
tstartvec= str2num(datestr(text1(imid,5),'HH MM SS')); %#ok<ST2NM>
tendvec= str2num(datestr(text1(imid,6),'HH MM SS')); %#ok<ST2NM>
tstart=(tstartvec(1)*60^2+tstartvec(2)*60+tstartvec(3))/(24*60^2);
tend=(tendvec(1)*60^2+tendvec(2)*60+tendvec(3))/(24*60^2);
startlocvec=abs(data2(:,1)-tstart);
endlocvec=abs(data2(:,1)-tend);
[m2,n2]=size(data2);
for i=1:m2
if min(startlocvec(:,1))==startlocvec(i,1);
istart=i;
elseif min(endlocvec(:,1))==endlocvec(i,1);
iend=i;
break
end
end
data3=data2(istart:iend,:);
disp('STATUS: Data Set Loaded.')
guidata(hObject,handles);
if str2num(MID)>=744
varlisttype=2;
else
varlisttype=1;
end
if varlisttype==1
varliststr=text2(8,1:94);
else
varliststr=text2(8,1:18);
end
descstr=1;
disp('STATUS: Assigning Variable Names...')
for i=1:numel(varliststr)
eval([varliststr{i} '=data3(:,i);']);
end
set(handles.DataTable,'Data',data3);
disp('STATUS: Data Saved to Table. Awaiting Plot Selections...')
guidata(hObject,handles);
% --- Executes on button press in PlotData.
function PlotData_Callback(hObject, eventdata, handles)
% hObject handle to PlotData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in xaxispopup.
function xaxispopup_Callback(hObject, eventdata, handles)
% hObject handle to xaxispopup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns xaxispopup contents as cell array
% contents{get(hObject,'Value')} returns selected item from xaxispopup
% --- Executes during object creation, after setting all properties.
function xaxispopup_CreateFcn(hObject, eventdata, handles)
% hObject handle to xaxispopup (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(handles.xaxispopup,'string',varliststr)
% --- Executes on selection change in yaxispopup.
function yaxispopup_Callback(hObject, eventdata, handles)
% hObject handle to yaxispopup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns yaxispopup contents as cell array
% contents{get(hObject,'Value')} returns selected item from yaxispopup
% --- Executes during object creation, after setting all properties.
function yaxispopup_CreateFcn(hObject, eventdata, handles)
% hObject handle to yaxispopup (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
0 comentarios
Respuestas (1)
Walter Roberson
el 15 de Jun. de 2012
Once you have a cell array of strings, S, then set() the String property of the handle of the pop-up menu to be S. This is exactly what is done by the above line of code
set(handles.xaxispopup,'string',varliststr)
0 comentarios
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!