About Matlab Gui (push button)
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have a problem with matlab gui. I use a push button to get a file and I want to open it using another push button but I couldn't do that. The code is;
if true
% code
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[dosyaadi,dosyayolu]=uigetfile('name.mid','Select a file');
if dosyaadi==0
return
end
nmat=readmidi_java(fullfile(dosyayolu,dosyaadi));
handles.nmat=nmat;
guidata(hObject,handles);
dosyaadi
end
Until that, everything is ok. I just want to use "dosyaadi" ,which is the original name of nmat, in another push button with the function 'system' but it didn't work. This is very normal because I didn't define what 'dosyaadi' is in that push button. How can I do that? I am new at matlab GUI, so I need a help!
if true
% code
function listen_Callback(hObject, eventdata, handles)
% hObject handle to listen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
nmat=handles.nmat;
system(dosyaadi);
end
0 commentaires
Réponses (1)
Image Analyst
le 26 Fév 2014
You get this from the first function: [dosyaadi,dosyayolu], which means dosyaadi is the base filename that the user chose, and dosyayolu is the folder that the user chose to store the file in. Ok, fine. Then you pass that full filename into readmidi_java() and accept the result into a variable called nmat. Then you say ""dosyaadi" ,which is the original name of nmat" - which I don't understand. Why does it have an original name, and a new name called nmat? Is nmat the base filename that has somehow been altered, based on the original value of dosyaadi? OK, whatever. Then you attach it to handles as a new field. That's fine. Then you call guidata so that handles will have that value inside any other function that access the handles structure. OK good. A bit strange, but okay.
Then you have a second function listen_Callback(). First it gets nmat. This will work because nmat is properly attached to handles. Then it calls system:
system(dosyaadi);
Well dosyaadi has not been defined inside listen_Callback(). It was only a local variable inside open_Callback() and vanished when you exited that function. So listen_Callback() will say that there is no dosyaadi variable when you call system(). To get it, you must have this line in both functions
global dosyaadi;
or else use setappdata and setappdata() like in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F There are some other methods there in the FAQ. If you want, you can just attach dosyaadi to handles like you did for nmat - you already know how to do that so that may be simplest for you.
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!