I tried your suggestions and I wrote it like this :
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename pathname] = uigetfile({'*.wav'}, 'Select File');
fullpathname = strcat (pathname, filename);
[data,fs] = wavread(filename);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%MODEL
% get a section of vowel
x = data(24120:25930);
ms20=fs/50; % minimum speech Fx at 50Hz
%
% plot waveform
t=(0:length(x)-1)/fs; % times of sampling instants
subplot(2,1,1);
plot(t,x);
legend('Waveform');
xlabel('Time (s)');
ylabel('Amplitude');
plot(handles.axes1,t,x);
%
% calculate autocorrelation
r=xcorr(x,ms20,'coeff');
%
% plot autocorrelation
d=(-ms20:ms20)/fs; % times of delays
subplot(2,1,2);
plot(d,r);
legend('Autocorrelation');
xlabel('Delay (s)');
ylabel('Correlation coeff.');
plot(handles.axes2,d,r);
ms2=fs/500 % maximum speech Fx at 500Hz
ms20=fs/50 % minimum speech Fx at 50Hz
% just look at region corresponding to positive delays
r=r(ms20+1:2*ms20+1)
[rmax,tx]=max(r(ms2:ms20))
fprintf('rmax=%g Fx=%gHz\n',rmax,fs/(ms2+tx-1));
But I get the following erros:
?? Undefined function or method 'data' for input arguments of type 'double'.
Error in ==> untitled>pushbutton2_Callback at 94
x = data(24120:25930);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> untitled at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)untitled('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback