hello i want to make GUI with 2 buttons. 1. button is for browse video file (it also connect path and file name into variable). this is my code in first button...
function pushbutton1_Callback(hObject, eventdata, handles)
[videoName,videoPathName]=uigetfile({'*.mp4';'*.*'},'File Selector')
assignin ('base','file',videoName);
assignin ('base','path',videoPathName);
fname = strcat(videoPathName,videoName);
assignin ('base','fname',fname);
so path and file name are in workspace in variable 'fname'
by second button a i want to run mfile 'run' that need path and file name from 1. button. so i wroute there only:
function pushbutton2_Callback(hObject, eventdata, handles)
run
in mfile run is code:
...
workingDir = 'C:\Users\lukino\Documents\MATLAB\temp';
mkdir(workingDir);
mkdir(workingDir,'images');
disp('urobil temp dir')
shuttleVideo = VideoReader(fname);
disp('nacital mp4')...
dirrectories are made but video can not open... it wrote error:
Undefined function or variable 'fname'
but if i want to run it from mfile idetor it works... what is wrong?

 採用された回答

nl2605
nl2605 2014 年 5 月 6 日

0 投票

I think the problem is that 'fname' is not getting transferred from one callback function to another. The solution is using setappdata and getappdata. I hope I am getting your problem right.

4 件のコメント

Lukas
Lukas 2014 年 5 月 6 日
can you apply it to my code? i do not uderstand how to use it
nl2605
nl2605 2014 年 5 月 6 日
In the callback function for pushbutton1 add this line:
setappdata(0,'fname',fname);
and in the other callback function add
fname = getappdata(0,'fname');
...
workingDir = 'C:\Users\lukino\Documents\MATLAB\temp';
mkdir(workingDir);
mkdir(workingDir,'images');
disp('urobil temp dir')
shuttleVideo = VideoReader(fname);
disp('nacital mp4')...
Lukas
Lukas 2014 年 5 月 6 日
thank you it works good. but now i do not see other variables that are used in other functions (for example in function run)...so i can not access to him. how can i change it?
nl2605
nl2605 2014 年 5 月 6 日
Variables used in a function are localized, I mean to say different functions don't share a common workspace. The variables will be deleted as soon as the function ends. If you want to use variables from one function to another again setappdata and getappdata will work.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

質問済み:

2014 年 5 月 6 日

コメント済み:

2014 年 5 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by