matlab gui make array public
-
16-02-2021 - |
Question
in my one of my callbacks, i load a wav file then plot it in an axes. in another callback, i try to play the wav file but its not working. please help, how can i play it??
function btnload_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile('*.wav','Select Data File');
[y,fs] = wavread([pathname filename]);
axes(handles.axes1)
plot(y);
title('ORIGINAL AUDIO SIGNAL');
ylabel('t');
guidata(hObject, handles); %updates the handles
function btnplay1_Callback(hObject, eventdata, handles)
soundsc(y,fs);
La solution
If you need to maintain application data in GUIDE-generated GUIs, one way is to use the handles
structure which gets passed around to all callback functions:
function btnload_Callback(hObject, eventdata, handles)
%# read WAV file
[filename, pathname] = uigetfile('*.wav','Select Data File');
[y,fs] = wavread([pathname filename]);
%# plot wave
axes(handles.axes1)
plot(y);
title('ORIGINAL AUDIO SIGNAL');
ylabel('t');
%# save it to handles structure
handles.y = y;
handles.fs = fs;
guidata(hObject, handles); %# updates the handles
end
function btnplay1_Callback(hObject, eventdata, handles)
%# retrieve the wave data, and play the sound
soundsc(handles.y, handles.fs);
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow