how can i update my edit box output in GUI

1 次查看(过去 30 天)
i have attached the full code of a simple IDMT device setting calculator, it is possible for the user to select device number 1 to 6 and each device has seven parameters, all user data is saved in a matrix. the program works fine except for i wish the edit box output data to update and display the correct matrix data when the device number is changed.
on line 189 i am trying to write a value to an edit box, the value is arbitrary for the time being, each time i get 'invalid handle object'
thanks in anticipation, Nathan
function varargout = new(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @new_OpeningFcn, ...
'gui_OutputFcn', @new_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 new is made visible.
function new_OpeningFcn(hObject, eventdata, handles, varargin)
clc
handles.internal_data = zeros(7,6);
% Choose default command line output for new
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
function varargout = new_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ct_Callback(hObject, eventdata, handles)
ct = str2double(get(hObject, 'String'));
if isnan(ct)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(1,b) = ct
handles.internal_data
% Save the new volume value
handles.ct = ct;
guidata(hObject,handles) %%inputs
function ct_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function plug_Callback(hObject, eventdata, handles)
plug = str2double(get(hObject, 'String'));
if isnan(plug)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(2,b) = plug
handles.internal_data
% Save the new volume value
handles.plug = plug;
guidata(hObject,handles)
function plug_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function time_Callback(hObject, eventdata, handles)
time = str2double(get(hObject, 'String'));
if isnan(time)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(3,b) = time
handles.internal_data
% Save the new volume value
handles.time = time;
guidata(hObject,handles)
function time_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function vref_Callback(hObject, eventdata, handles)
vref = str2double(get(hObject, 'String'));
if isnan(vref)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(4,b) = vref
handles.internal_data
% Save the new volume value
handles.vref = vref;
guidata(hObject,handles)
function vref_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function vprot_Callback(hObject, eventdata, handles)
vprot = str2double(get(hObject, 'String'));
if isnan(vprot)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(5,b) = vprot
handles.internal_data
% Save the new volume value
handles.vprot = vprot;
guidata(hObject,handles)
function vprot_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function para_Callback(hObject, eventdata, handles)
para = str2double(get(hObject, 'String'));
if isnan(para)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(6,b) = para
handles.internal_data
% Save the new volume value
handles.para = para;
guidata(hObject,handles)
function para_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function listbox1_Callback(hObject, eventdata, handles) %%listbox inputs
b = get(handles.dev_sel, 'value')
a = get(handles.listbox1, 'value')
handles.internal_data(7,b) = a
handles.internal_data
% Save the new listbox value
guidata(hObject,handles)
function listbox1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function dev_sel_Callback(hObject, eventdata, handles)
b = 1 %get(handles.dev_sel, 'value')
a = num2str (7) %(handles.internal_data(1,b))
handles
set(handles.ct, 'String', a) ;
function dev_sel_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
data_Voltage_ratio = zeros(1,6)
data_coeff = zeros(1,6)
trip_time = zeros(6,12)
fault_mag_series = [1.2, 2,3,4,5,6,7,8,9,10,20];
extremely = [80 , 2 ]; %scalar , exp
very = [13.5, 1 ];
standard = [0.14, 0.02];
long_time = [120 , 1 ];
x = 1 % repeated for each device
while x < 7
data_Voltage_ratio(x) = handles.internal_data(5,x) / handles.internal_data(4,x); % v/r = vprot / vref
data_Voltage_ratio(isnan(data_Voltage_ratio))=0; % replace nan with zero
data_coeff(x) = handles.internal_data(6,x) * handles.internal_data(2,x); % coeff = para * plug
m=1;
while m<12
fault_current_PU(x,m) = data_coeff(x) * fault_mag_series(m); % populates fault current values
fault_current_corrected(x,m) = fault_current_PU(x,m)* handles.internal_data(1,x) * data_Voltage_ratio(x) /1000;
if handles.internal_data(7,x) == 2
trip_time(x,m) = (extremely(1)*handles.internal_data(3,x)) / (((fault_current_PU(x,m) / (handles.internal_data(2,x) * handles.internal_data(6,x)))^extremely(2))-1)
elseif handles.internal_data(7,x) == 3
trip_time(x,m) = (very(1)*handles.internal_data(3,x)) / (((fault_current_PU(x,m) / (handles.internal_data(2,x) * handles.internal_data(6,x)))^very(2))-1)
elseif handles.internal_data(7,x) == 4
trip_time(x,m) = (standard(1)*handles.internal_data(3,x)) / (((fault_current_PU(x,m) / (handles.internal_data(2,x) * handles.internal_data(6,x)))^standard(2))-1)
elseif handles.internal_data(7,x) == 5
trip_time(x,m) = (long_time(1)*handles.internal_data(3,x)) / (((fault_current_PU(x,m) / (handles.internal_data(2,x) * handles.internal_data(6,x)))^long_time(2))-1)
end
m=m+1;
end
if handles.internal_data(7,x)~= 1
loglog (fault_current_corrected(x,1:11), trip_time(x,1:11))
grid on
hold on
title('Required Protection Settings');
xlabel('Fault Current (KA)')
ylabel('Time to Operate (Seconds)')
axis([0.01 100 0.1 100])
end
x=x+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2 个评论
Jan
Jan 2013-3-11
Please post the relevant part of the code only and format it properly. Which one is the line 189?
nathan
nathan 2013-3-11
编辑:Walter Roberson 2013-3-12
ok this section of code executes each time a user inputs a ct ratio
function ct_Callback(hObject, eventdata, handles)
ct = str2double(get(hObject, 'String'));
if isnan(ct)
set(hObject, 'String', 0);
errordlg('Input must be a number','Error');
end
b = get(handles.dev_sel, 'value')
handles.internal_data(1,b) = ct
handles.internal_data
% Save the new volume value
handles.ct = ct;
guidata(hObject,handles)
the code saves the user entered data in a matrix, when the user selects a different device the input is saved in the next colomn in the matrix each time the device select listbox function is used i would like the output data to update i am now trying to use the following code segment
function dev_sel_Callback(hObject, eventdata, handles)
b = get(handles.dev_sel, 'value')
a = (handles.internal_data(1,b))
handles.ct = a;
guidata(hObject,handles)
handles.ct doesnt seem to be updating.
thanks nathan

请先登录,再进行评论。

采纳的回答

nathan
nathan 2013-3-13
编辑:Walter Roberson 2013-3-13
i have used this method you suggest
set(handles.ct, 'String', num2str(handles.internal_data(1,b))
in the following form
function dev_sel_Callback(hObject, eventdata, handles)
b = get(handles.dev_sel, 'value')
c = (handles.internal_data(1,b))
set(handles.ct, 'string', num2str(c))
which works perfectly!!
thank you all very much

更多回答(2 个)

John Petersen
John Petersen 2013-3-11
To update the handles.ct (I'm guessing this is your edit text box)
function dev_sel_Callback(hObject, eventdata, handles)
b = get(handles.dev_sel,'value');
set(handles.ct, 'value', get(handles.internal_data(1,b));

nathan
nathan 2013-3-12
thank you very much for your feedback John, with your help i'm definitely getting closer i am now using the code segment you suggest but now get the following error
??? Error using ==> set Conversion to double from struct is not possible.
the information is saved in a matrix in double form so i am not entirely sure why i achieve this error??
appreciate your time, Nathan
  1 个评论
Walter Roberson
Walter Roberson 2013-3-12
The get(handles.internal_data(1,b)) is causing that. Possibly what you want is
set(handles.ct, 'Value', handles.internal_data(1,b))
or maybe
set(handles.ct, 'String', num2str(handles.internal_data(1,b))

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by