Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

error while calling a programatic gui from a guide gui

1 Ansicht (letzte 30 Tage)
salamay
salamay am 4 Aug. 2011
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I have a main GUI created using GUIDE and I am calling a programmatic GUI (dialog box with some inputs)by clicking pushbutton callback from the main GUI.
by doing so MATLAB give the following error
??? Error using ==> WSM>getLASandXLS
Too many output arguments.
Error in ==> WSM>impWizard_Callback at 259
files = getLASandXLS;
The following is the code for my programmatic GUI which works fine from commandline but not inside the pussbutton callback of main GUI
function varargout = getLASandXLS(varargin)
% getLASandXLS Get file names for processing data
% click browse push buttons. Clicking the buttons
% populates the edit boxes. click OK to finsh
mInputArgs = varargin; % Command line arguments when invoking the GUI
mOutputArgs = {}; % Variable for storing output when GUI returns
% Initialize and hide the GUI as it is being constructed.
w = 500; % pixels
h = 120; % pixels
f = figure('Visible','off', 'Color',[.94 .94 .94],'MenuBar','none',...
'Name','Choose data files','NumberTitle','off',...
'ToolBar','none','Resize','off','Position',[250,500,w,h]);
htextLAS = uicontrol('Style','text',...
'String','Log data file path',...
'Position',[10,h-43.5,100,25]);
htextXLS = uicontrol('Style','text',...
'String','Lab data file path',...
'Position',[10,h-78.5,100,25]);
heditLAS = uicontrol('Style','edit', ...
'BackgroundColor',[1 1 1],...
'enable', 'on',...
'String','Choose LAS file',...
'Position',[120,h-40,300,25]);
heditXLS = uicontrol('Style','edit',...
'BackgroundColor',[1 1 1],...
'enable', 'on',...
'String','Choose XLS file',...
'Position',[120,h-75,300,25]);
hpbtnLAS = uicontrol('Style','pushbutton',...
'String','Browse',...
'Callback',{@browseLAS_Callback},...
'Position',[430,h-40,60,25]);
hpbtnXLS = uicontrol('Style','pushbutton',...
'String','Browse',...
'Callback',{@browseXLS_Callback},...
'Position',[430,h-75,60,25]);
hpbtnOK = uicontrol('Style','pushbutton',...
'String','OK',...
'Callback',{@ok_Callback},...
'Position',[430,h-110,60,25]);
hpbtnCancel = uicontrol('Style','pushbutton',...
'String','Cancel',...
'Callback',{@cancel_Callback},...
'Position',[360,h-110,60,25]);
movegui(f, 'center');
set(f,'Visible','on')
uiwait(f);
% varargout = files;
mOutputArgs{1} =files;
if nargout>0
[varargout{1:nargout}] = mOutputArgs{:};
end
function browseLAS_Callback(source, eventdata)
filter_spec={'*.las', 'Well log files (*.las)'; ...
'*.*', 'All files (*.*)'};
dialogue='Read LAS file';
[fname,pname] = uigetfile(filter_spec, dialogue);
filename = strcat(pname, fname);
if fopen(filename) == -1
error('No file selected');
end
set(heditLAS, 'string', filename);
end
function browseXLS_Callback(source, eventdata)
filter_spec={'*.Xls*', 'Core data sheets (*.Xls)'; ...
'*.*', 'All files (*.*)'};
dialogue='Read Excel file';
[fname,pname] = uigetfile(filter_spec, dialogue);
filename = strcat(pname, fname);
if fopen(filename) == -1
error('No file selected');
end
set(heditXLS, 'string', filename);
end
function cancel_Callback(source, eventdata)
disp('Import data dialog was cancelled');
files{1} = [];
files{2} = [];
uiresume;
delete(f);
end
function ok_Callback(source, eventdata)
files{1} = get(heditLAS,'String');
files{2} = get(heditXLS,'String');
uiresume;
delete(f);
end
end

Antworten (1)

Walter Roberson
Walter Roberson am 4 Aug. 2011
[varargout{1:nargout}] = deal(mOutputArgs{1:nargout});
or, better,
if nargout > numel(mOutputArgs)
mOutputArgs(end+1:nargout) = {};
end
varargout(1:nargout) = mOutputArgs(1:nargout);
When the number of values in mOutputArgs was more than the number of output arguments, the code you were using had a mismatch between the left and right hand side. The "or, better" version also protects against the number of output arguments being larger than the number of available values.
  2 Kommentare
salamay
salamay am 5 Aug. 2011
I used your first method but still gives the same error while using it inside another GUI pushbutton callback.
I have a feeling that getLASandXLS doesn not have any issues but theres gotta be something wrong while calling it from another GUIDE generated gui
salamay
salamay am 5 Aug. 2011
Oh I found the problem.
I had the same function in the main gui which i initially was trying to write and then decided to make it an external function. Now that I have deleted that it works just fine.
Thanks anyway for your help!

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by