From: Adam Chapman on 14 Jul 2010 07:17 On Jul 14, 11:08 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk> wrote: > On Jul 14, 10:56 am, Adam Chapman <adamchapman1...(a)hotmail.co.uk> > wrote: > > > On Jul 14, 10:48 am, "us " <u...(a)neurol.unizh.ch> wrote: > > > > Adam Chapman > > > > > Aha! That's making more sense! > > > > > Does it need to be a handle or can it remain a variable? I would of > > > > thought it should be a handle, because on line 63: handles.output = > > > > hObject; > > > > > I would have thought hObject is a handle, but I'll check now > > > > well... > > > depending on HOW you use the field's content later on, you could simply write... > > > > handles.batteryCapacity=200; % <- :-) > > > > us > > > I just tried that before your response, but the set command is nice to > > put default values in the edit boxes of the GUI. > > > The set command gives an error if I run the GUI script when the GUI is > > already open, otherwise the set command doesn't complian. > > > I've pasted my current script below incase I've made changes that you > > haven't seen. Ive practically been changing things through trial and > > error ... > > > ------------------------ > > > function varargout = battery_gui(varargin) > > > %clc > > > % BATTERY_GUI M-file for battery_gui.fig > > % BATTERY_GUI, by itself, creates a new BATTERY_GUI or raises the > > existing > > % singleton*. > > % > > % H = BATTERY_GUI returns the handle to a new BATTERY_GUI or the > > handle to > > % the existing singleton*. > > % > > % BATTERY_GUI('CALLBACK',hObject,eventData,handles,...) calls the > > % local > > % function named CALLBACK in BATTERY_GUI.M with the given input > > arguments. > > % > > % BATTERY_GUI('Property','Value',...) creates a new BATTERY_GUI > > or raises the > > % existing singleton*. Starting from the left, property value > > pairs > > % are > > % applied to the GUI before battery_gui_OpeningFcn gets called. > > An > > % unrecognized property name or invalid value makes property > > application > > % stop. All inputs are passed to battery_gui_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 battery_gui > > > % Last Modified by GUIDE v2.5 14-Jul-2010 08:26:32 > > > % Begin initialization code - DO NOT EDIT > > gui_Singleton = 1; > > gui_State = struct('gui_Name', mfilename, ... > > 'gui_Singleton', gui_Singleton, ... > > 'gui_OpeningFcn', @battery_gui_OpeningFcn, ... > > 'gui_OutputFcn', @battery_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 battery_gui is made visible. > > function battery_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 command line arguments to battery_gui (see VARARGIN) > > > % Choose default command line output for battery_gui > > 1 > > handles.output = hObject; > > > %b=ishandle(hObject) > > 2 > > % Update handles structure > > guidata(hObject, handles); > > %handles2=handles > > 3 > > initialize_gui(hObject, handles, false); > > %c=get(hObject) > > 4 > > % UIWAIT makes battery_gui wait for user response (see UIRESUME) > > % uiwait(handles.figure1); > > > function initialize_gui(fig_handle, handles, isconfirm) > > %Set up with values > > which handles -all; > > disp(handles); > > % class(handles) > > %handles > > %a=ishandle(handles.batteryCapacity) > > > set(handles.batteryCapacity, 'String', '200'); > > set(handles.cellNum, 'String', '98'); > > set(handles.maxDischarge, 'String','600'); > > set(handles.maxRecharge, 'String', '400'); > > > handles.batteryCapacity=200; > > handles.cellNum=98; > > handles.maxDischarge=600; > > handles.maxRecharge=400; > > > %handles > > %handles verbose debugging > > > % Update handles structure > > guidata(handles.figure1, handles); > > > % --- Outputs from this function are returned to the command line. > > function varargout = battery_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 batteryCapacity_Callback(hObject, eventdata, handles) > > % hObject handle to batteryCapacity (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 batteryCapacity as > > text > > % str2double(get(hObject,'String')) returns contents of > > batteryCapacity as a double > > handles.batteryCapacity = str2double(get(hObject, 'String')); > > %handles.metricdata.evMaxTorque = handles.evMaxTorque; > > guidata(hObject,handles) > > handles > > > % --- Executes during object creation, after setting all properties. > > function batteryCapacity_CreateFcn(hObject, eventdata, handles) > > % hObject handle to batteryCapacity (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 > > > function maxDischarge_Callback(hObject, eventdata, handles) > > % hObject handle to maxDischarge (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 maxDischarge as > > text > > % str2double(get(hObject,'String')) returns contents of > > maxDischarge as a double > > > % --- Executes during object creation, after setting all properties. > > function maxDischarge_CreateFcn(hObject, eventdata, handles) > > % hObject handle to maxDischarge (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. > > handles.maxDischarge = str2double(get(hObject, 'String')); > > if ispc && isequal(get(hObject,'BackgroundColor'), > > get(0,'defaultUicontrolBackgroundColor')) > > set(hObject,'BackgroundColor','white'); > > end > > > function maxRecharge_Callback(hObject, eventdata, handles) > > % hObject handle to maxDischarge (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 maxDischarge as > > text > > % str2double(get(hObject,'String')) returns contents of > > maxDischarge as a double > > > % --- Executes during object creation, after setting all properties. > > function maxRecharge_CreateFcn(hObject, eventdata, handles) > > % hObject handle to maxDischarge (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. > > handles.maxRecharge = str2double(get(hObject, 'String')); > > if ispc && isequal(get(hObject,'BackgroundColor'), > > get(0,'defaultUicontrolBackgroundColor')) > > set(hObject,'BackgroundColor','white'); > > end > > > % --- Executes on button press in confirm. > > function confirm_Callback(hObject, eventdata, handles) > > % hObject handle to confirm (see GCBO) > > % eventdata reserved - to be defined in a future version of MATLAB > > % handles structure with handles and user data (see GUIDATA) > > > load_system('RREV_v4.mdl') > > > %number of motors: > > set_param('RREV_v4/Electric Drive System/Kokam 200 Ah/Recharge/Ah > > Converter/Ah Capacity','Value',num2str(handles.batteryCapacity)) > > set_param('RREV_v4/Electric Drive System/Kokam 200 Ah/Recharge/Battery > > Current Limit','Gain',num2str(handles.maxRecharge)) > > %set_param('RREV_v4/Electric Drive System/UQM145 Motor x2/ > > Gain2','Gain',num2str(handles.evMotorNum)) > > > %save model > > save_system > > > function cellNum_Callback(hObject, eventdata, handles) > > % hObject handle to cellNum (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 cellNum as text > > % str2double(get(hObject,'String')) returns contents of cellNum > > as a double > > > % --- Executes during object creation, after setting all properties. > > function cellNum_CreateFcn(hObject, eventdata, handles) > > % hObject handle to cellNum (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. > > handles.cellNum = str2double(get(hObject, 'String')); > > if ispc && isequal(get(hObject,'BackgroundColor'), > > get(0,'defaultUicontrolBackgroundColor')) > > set(hObject,'BackgroundColor','white'); > > end > > > ------------------------ Hide quoted text - > > > - Show quoted text - > > OK It's happy to use the set command when the GUI figure is not > already open. If the GUI is already open and I run its script, it > starts screaming. > > No idea why the handle is invalid when the figure is already open > though Oh well, I just made the window close on pressing the "confirm " button. That'll do! Thanks again for all your help
From: Steven Lord on 14 Jul 2010 10:18 "us " <us(a)neurol.unizh.ch> wrote in message news:i1k0ae$k07$1(a)fred.mathworks.com... > Adam Chapman >> the whole output is: handles is a variable. >> figure1: 1.5000e+003 >> uipanel1: 1.5010e+003 >> text8: 1.5130e+003 >> confirm: 1.5120e+003 >> Multi: [1.5110e+003 1.5090e+003] >> maxRecharge: 400 >> text4: 1.5080e+003 >> maxDischarge: 600 >> cellNum: 98 >> text3: 1.5050e+003 >> text2: 1.5040e+003 >> batteryCapacity: 200 > >> ??? Error using ==> set >> Invalid handle object. > > well... THAT explains it, though: > > batteryCapacity: 200 % <- is NOT a handle... Technically it could be, if the OP had done the following before creating their handles structure: figure(200) but I agree with you that maxRecharge, maxDischarge, cellNum, and batteryCapacity look suspiciously large to be figure handles, and figures (and the root object which ALWAYS has handle 0) are generally the only graphics objects that get integer-valued handles. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: us on 14 Jul 2010 10:27 "Steven Lord" <slord(a)mathworks.com> wrote in message <i1kgv0$ku0$1(a)fred.mathworks.com>... > > "us " <us(a)neurol.unizh.ch> wrote in message > news:i1k0ae$k07$1(a)fred.mathworks.com... > > Adam Chapman > >> the whole output is: handles is a variable. > >> figure1: 1.5000e+003 > >> uipanel1: 1.5010e+003 > >> text8: 1.5130e+003 > >> confirm: 1.5120e+003 > >> Multi: [1.5110e+003 1.5090e+003] > >> maxRecharge: 400 > >> text4: 1.5080e+003 > >> maxDischarge: 600 > >> cellNum: 98 > >> text3: 1.5050e+003 > >> text2: 1.5040e+003 > >> batteryCapacity: 200 > > > >> ??? Error using ==> set > >> Invalid handle object. > > > > well... THAT explains it, though: > > > > batteryCapacity: 200 % <- is NOT a handle... > > Technically it could be, if the OP had done the following before creating > their handles structure: > > figure(200) correct... however, i looked at his/her code and (in a later post) referred to the command handles.batteryCapacity = str2double(get(hObject, 'String')); which clearly shows that the field's val cannot be a handle... us
From: Steven Lord on 14 Jul 2010 12:57 "us " <us(a)neurol.unizh.ch> wrote in message news:i1khg8$sah$1(a)fred.mathworks.com... > "Steven Lord" <slord(a)mathworks.com> wrote in message > <i1kgv0$ku0$1(a)fred.mathworks.com>... >> "us " <us(a)neurol.unizh.ch> wrote in message >> news:i1k0ae$k07$1(a)fred.mathworks.com... *snip* >> > well... THAT explains it, though: >> > >> > batteryCapacity: 200 % <- is NOT a handle... >> >> Technically it could be, if the OP had done the following before creating >> their handles structure: >> >> figure(200) > > correct... > however, i looked at his/her code and (in a later post) referred to the > command > > handles.batteryCapacity = str2double(get(hObject, 'String')); > > which clearly shows that the field's val cannot be a handle... Reading ahead in the story, eh? Isn't that cheating? *grin* -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
First
|
Prev
|
Pages: 1 2 3 4 Prev: Making some parts of image fully transparent Next: Extracting subvector between boundary |