How can I take multiple selections from four listboxes and initialize the selections to varargout to be an output of the function? The error my code throws is at the bottom of my code.

1 回表示 (過去 30 日間)
function varargout = ConfigurationsAndSimulationDetails(varargin)
% CONFIGURATIONSANDSIMULATIONDETAILS MATLAB code for ConfigurationsAndSimulationDetails.fig
% CONFIGURATIONSANDSIMULATIONDETAILS, by itself, creates a new CONFIGURATIONSANDSIMULATIONDETAILS or raises the existing
% singleton*.
%
% H = CONFIGURATIONSANDSIMULATIONDETAILS returns the handle to a new CONFIGURATIONSANDSIMULATIONDETAILS or the handle to
% the existing singleton*.
%
% CONFIGURATIONSANDSIMULATIONDETAILS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CONFIGURATIONSANDSIMULATIONDETAILS.M with the given input arguments.
%
% CONFIGURATIONSANDSIMULATIONDETAILS('Property','Value',...) creates a new CONFIGURATIONSANDSIMULATIONDETAILS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ConfigurationsAndSimulationDetails_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ConfigurationsAndSimulationDetails_OpeningFcn via varargin.
%
% *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 ConfigurationsAndSimulationDetails
% Last Modified by GUIDE v2.5 20-Feb-2019 02:50:08
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ConfigurationsAndSimulationDetails_OpeningFcn, ...
'gui_OutputFcn', @closingfnc, ...
'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 ConfigurationsAndSimulationDetails is made visible.
function ConfigurationsAndSimulationDetails_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 command line arguments to ConfigurationsAndSimulationDetails (see VARARGIN)
% Choose default command line output for ConfigurationsAndSimulationDetails
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ConfigurationsAndSimulationDetails wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function ConfigurationsAndSimulationDetails_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
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (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 listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject handle to listbox2 (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 listbox2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox2
% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox3.
function listbox3_Callback(hObject, eventdata, handles)
% hObject handle to listbox3 (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 listbox3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox3
% --- Executes during object creation, after setting all properties.
function listbox3_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox4.
function listbox4_Callback(hObject, eventdata, handles)
% hObject handle to listbox4 (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 listbox4 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox4
% --- Executes during object creation, after setting all properties.
function listbox4_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox5.
function listbox5_Callback(hObject, eventdata, handles)
% hObject handle to listbox5 (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 listbox5 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox5
% --- Executes during object creation, after setting all properties.
function listbox5_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 selection change in listbox6.
function listbox6_Callback(hObject, eventdata, handles)
% hObject handle to listbox6 (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 listbox6 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox6
% --- Executes during object creation, after setting all properties.
function listbox6_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
powertrainArray = get(handles.listbox1, 'Value')
engineArray = get(handles.listbox2, 'Value')
motorArray = get(handles.listbox3, 'Value')
batteryArray = get(handles.listbox4, 'Value')
closingfnc(powertrainArray,engineArray,motorArray,batteryArray)
close;
function varargout = closingfnc(powertrainArray, engineArray, motorArray, batteryArray)
varargout{:} = [powertrainArray, engineArray, motorArray, batteryArray]
%Not enough input arguments.
%Error in ConfigurationsAndSimulationDetails>closingfnc (line 227)
varargout{:} = [powertrainArray, engineArray, motorArray, batteryArray]
%Error in gui_mainfcn (line 264)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
%Error in ConfigurationsAndSimulationDetails (line 42)
gui_mainfcn(gui_State, varargin{:});

回答 (1 件)

Image Analyst
Image Analyst 2019 年 2 月 21 日
編集済み: Image Analyst 2019 年 2 月 21 日
Get rid of the braces {:}
varargout = [powertrainArray, engineArray, motorArray, batteryArray]
Make sure each of those is a row vector or if they're column vectors, make sure they all have the same number of rows in them.
Or have it be a cell array like
varargout = {powertrainArray, engineArray, motorArray, batteryArray}
Actually, this may be better since it keeps the arrays separate - each array in its own cell.
  1 件のコメント
Brandon McDonald
Brandon McDonald 2019 年 2 月 21 日
I tried the curly brackets you suggested and got the same error.
I tried the regular brakets and got this error now:
Variable output array "varargout" must be a cell array.
Error in ConfigurationsAndSimulationDetails>closingfnc (line 226)
function varargout = closingfnc(powertrainArray, engineArray, motorArray, batteryArray)
Error in ConfigurationsAndSimulationDetails>pushbutton1_Callback (line 223)
closingfnc(powertrainArray,engineArray,motorArray,batteryArray)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ConfigurationsAndSimulationDetails (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ConfigurationsAndSimulationDetails('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by