how to make passing parametes between GUI and *.m files

1 Ansicht (letzte 30 Tage)
Fitroh Amaluddin
Fitroh Amaluddin am 5 Jan. 2015
Beantwortet: Geoff Hayes am 14 Jan. 2015
%================== in my gui file
mygui.m
-------
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.avi';'*.mpeg'}, 'Pilih Video');
set(handles.edit1,'string',[pathname filename]);
guidata(hObject, handles);
%call my 'myfile.m'
mymfile
%================== in my *.m file
mymfile.m
-------
function obj = setupSystemObjects()
urlfiles = get(handles.edit1,'string');
obj.reader = vision.VideoFileReader(urlfiles);
how to passing '[pathname filename]' in 'handels.edit1' to variabel 'urlfiles' in my 'mymfiles.m' cause i still get error.
"The class "handles" is undefined. Perhaps Java is not running."

Antworten (1)

Geoff Hayes
Geoff Hayes am 14 Jan. 2015
Fitroh - why not just pass the list of videos to your setupSystemObjects function (which is presumably saved to a file called setupSystemObjects.m and not in myfile.m) as an input parameter? Change the signature and body of this function to
function obj = setupSystemObjects(videoFiles)
obj.reader = vision.VideoFileReader(videoFiles);
% etc.
and then call this function from your callback as
function pushbutton1_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.avi';'*.mpeg'}, 'Pilih Video');
videoFiles = [pathname filename];
set(handles.edit1,'string', videoFiles);
setupSystemObjects(videoFiles);
Try the above and see what happens! The alternative is to use global variables, but that is something that can be avoided here.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by