matlab gui make array public

时间:2011-10-30 06:11:24

标签: arrays user-interface matlab matlab-guide

在我的一个回调中,我加载一个wav文件,然后将其绘制在一个轴上。  在另一个回调中,我尝试播放wav文件,但它无法正常工作。  请帮忙,我怎么玩呢?

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); 

1 个答案:

答案 0 :(得分:3)

如果您需要在GUIDE生成的GUI中维护application data,一种方法是使用传递给所有回调函数的handles结构:

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