question concerning subfunction interaction between GUIs

1 view (last 30 days)
hello, I have encountered a problem in trying to create a function interaction between two GUIs.
description: this gui interaction is surposed to load and open a .txt file when a pushbutton is pushed in the 2nd GUI. Furthermore to process this .txt file and finally print two values in two diferent "static text" fields.
My main function is where the function is defined, and stored in appdata, this is done as follows, within the main functions opening function
setappdata(0, 'hMainGui', gcf);
setappdata(gcf, 'fhtxtConverter', @txtConverter);
My function is defined as follows, still within the main gui
function txtConverter
%this function is surposed to process text files and should be callable
%from every GUI
fileName_1 = uigetfile('*.txt');
fileName_2 = fopen(fileName_1);
fileName = textscan(fileName_2, '%*11s %2s %*1s %2s %*1s %6s %*2s %q','HeaderLines', 1);
fclose(fileName_2);
hour_temp = fileName{1,1};
min_temp = fileName{1,2};
sec_temp = fileName{1,3};
value = fileName{1,4};
L = length(value);
%processing the information
for i=1:L
%converting time into a inclining secund paragraph
time(i) = str2double(hour_temp(i))*60*60+str2double(min_temp(i))*60+str2double(sec_temp(i))-(str2double(hour_temp(1))*60*60+str2double(min_temp(1))*60+str2double(sec_temp(1)));
%converting to double while swapping all commas with dots
data(i) = str2double(regexprep(value(i), ',' , '.'));
end
set(handles.range_from, 'string', num2str(time(1)));
set(handles.range_to , 'string', num2str(time(end)));
Within my second GUI I now call this function to act its purpose
function load_data_Callback(hObject, eventdata, handles)
% hObject handle to load_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%
hMainGui = getappdata(0, 'hMainGui');
fhtxtConverter = getappdata(hMainGui, 'fhtxtConverter');
feval(fhtxtConverter);
So my problems is that it seems I connot use the handle structure in the way that I am, in the function txtConverter. When I run my GUI han follow this path, the following error message occurs
??? Undefined variable "handles" or class "handles.range_from".
Error in ==> main_gui_v1>txtConverter at 1147
set(handles.range_from, 'string', num2str(time(1)));
Error in ==> browse_data_w_1>load_data_Callback at 86
feval(fhtxtConverter);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> browse_data_w_1 at 42
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback
I am thinking that another solution onto how I use my handles is needed, but I am not sure.
any suggestions?

Accepted Answer

Robert Cumming
Robert Cumming on 29 Apr 2011
The variable
handles
in your function txtConverter is undefined. You need to pass in (or get from findobj or similar) the handles as a variable so that the txtConverter function can interact with the handles variable.
  1 Comment
Steffan
Steffan on 29 Apr 2011
thank you very much Robert
I will try to see if I can figure out, how to do this correctly when the function is called to several GUIs.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!