Errors and Warnings on Very Simple GUI
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi Everyone,
I'm creating a simple GUI which plots data selected from in the directory. Having only written two parts of the script so far after making the GUI with GUIDE, I'm now encounterring errors I can't work out how to fix! I'm very new to MATLAB and am currently teaching myself how to make GUIs which will be useful to me to plot experimental data easily.
My code is as follows;
% --------------------------------------------------------------------
function varargout = listbox_x_CreateFcn(h, eventdata, handles, varargin)
D = dir('*.mat'); %Scan directory for .mat files
listbox_x_string = {D(:).name}; %Set to display full name of files found
handles.listbox_x_string = listbox_x_string;
handles.listbox_x = set(h,'String',handles.listbox_x_string); %Display list of files in ListBox_x
edit_x_string = get(handles.edit_x(varargin,'String'));
n = length(edit_x_string);
handles.n = n;
if handles.n >= 1
if strncmpi(handles.edit_x_string,listbox_x_string,handles.n) == 0
set(h,'String',' ');
elseif strncmpi(handles.edit_x_string,listbox_x_string.handles.n) >= 1
set(h,'String',listbox_x_string(strncmpi(handles.edit_x_string,listbox_x_string,handles.n)));
end
end
guidata(gcbo,handles)
% --------------------------------------------------------------------
function varargout = listbox_y_CreateFcn(h, eventdata, handles, varargin)
D = dir('*.mat'); %Scan directory for .mat files
listbox_y_string = {D(:).name}; %Set to display full name of files found
handles.listbox_y_string = listbox_y_string;
handles.listbox_y = set(h,'string',handles.listbox_y_string); %Display list of files in ListBox_y
edit_y_string = get(handles.edit_y(varargin,'String'));
m = length(edit_y_string);
handles.m = m;
if handles.m >= 1
if strncmpi(handles.edit_y_string,listbox_y_string,handles.m) == 0
set(h,'String',' ');
elseif strncmpi(handles.edit_y_string,listbox_y_string.handles.m) >= 1
set(h,'String',listbox_y_string(strncmpi(handles.edit_y_string,listbox_y_string,handles.m)));
end
end
guidata(gcbo,handles)
% --------------------------------------------------------------------
function varargout = edit_x_CreateFcn(h, eventdata, handles, varargin)
handles.edit_x = edit_x;
guidata(gcbo,handles)
% --------------------------------------------------------------------
function varargout = edit_y_CreateFcn(h, eventdata, handles, varargin)
handles.edit_y = edit_y;
guidata(gcbo,handles)
And the errors I'm already receiving on launch of the GUI are the following;
Warning: One or more output arguments not assigned during call to 'set'.
> In C:\Users\roze wesby.RWES-PC1\MATLAB\Version 1\main_menu.m (listbox_y_CreateFcn) at line 101
In C:\Users\roze wesby.RWES-PC1\MATLAB\Version 1\main_menu.m at line 29
In C:\MATLAB6p1\toolbox\matlab\iofun\hgload.m at line 117
In C:\MATLAB6p1\toolbox\matlab\graphics\openfig.m at line 57
In C:\MATLAB6p1\toolbox\matlab\general\open.m at line 115
In C:\MATLAB6p1\toolbox\matlab\uitools\uiopen.m at line 137
Reference to non-existent field 'edit_y'.
Undefined function or variable 'edit_y'.
Warning: One or more output arguments not assigned during call to 'set'.
> In C:\Users\roze wesby.RWES-PC1\MATLAB\Version 1\main_menu.m (listbox_x_CreateFcn) at line 79
In C:\Users\roze wesby.RWES-PC1\MATLAB\Version 1\main_menu.m at line 29
In C:\MATLAB6p1\toolbox\matlab\iofun\hgload.m at line 117
In C:\MATLAB6p1\toolbox\matlab\graphics\openfig.m at line 57
In C:\MATLAB6p1\toolbox\matlab\general\open.m at line 115
In C:\MATLAB6p1\toolbox\matlab\uitools\uiopen.m at line 137
Reference to non-existent field 'edit_x'.
Undefined function or variable 'edit_x'.
I'd be so grateful for any insight you could give me with this because I'm scared to continue without fixing these issues.
Thanks in advance,
Rosie
P.S. I'm using MATLAB 6.1
0 commentaires
Réponse acceptée
Robert Cumming
le 1 Août 2012
I'd advise you to look at GUI FEX which contains lots of examples on how to learn to work with GUI's
0 commentaires
Plus de réponses (1)
Image Analyst
le 1 Août 2012
Well this doesn't look good:
handles.edit_x = edit_x;
edit_x is the name of your GUI and you're adding a line to the startup code of edit_x that basically say to run the edit_x GUI and take the output and assign it to a field, called edit_x, of the handles structure. But how can you run edit_x when you're not done launching it the first time? What are you intending with this line?
3 commentaires
Image Analyst
le 1 Août 2012
Wow. You really need to watch some of Doug Hull's videos on making GUIs. You're playing with fire if you're messing around with the arg list of the CreateFcn - I wouldn't touch that if I were you. I thought that was the name of your GUI but it's not, it's the edit box create function that you're dangerously messing with. Again, I wouldn't do that. Pretty much a good rule of thumb is to only put code in the regular callbacks (for click, change, etc.) and not to put code in the CreateFcn because you'll probably just end up screwing it up.
You can make a listbox contain an edit field if you do something like this:
editBoxContents = get(handles.edit_x, 'String');
set(handles.listbox1, 'String', editBoxContents);
handles is available to all GUI control callbacks (but not your own custom written functions unless you pass it in via the arg list). So you can put that in any callback you want - wherever it makes sense to do so.
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!