function varargout = testGUI(varargin)
% TESTGUI MATLAB code for testGUI.fig
% TESTGUI, by itself, creates a new TESTGUI or raises the existing
% singleton*.
%
% H = TESTGUI returns the handle to a new TESTGUI or the handle to
% the existing singleton*.
%
% TESTGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTGUI.M with the given input arguments.
%
% TESTGUI('Property','Value',...) creates a new TESTGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before testGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to testGUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help testGUI
% Last Modified by GUIDE v2.5 08-Jun-2015 19:04:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testGUI_OpeningFcn, ...
'gui_OutputFcn', @testGUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before testGUI is made visible.
function testGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to testGUI (see VARARGIN)
% Choose default command line output for testGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes testGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = testGUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in opentxt.
function opentxt_Callback(hObject, eventdata, handles)
% hObject handle to opentxt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,path]=uigetfile('*.txt','打开要统计的文本文件')
filenameandpath=strcat(path,filename)
handles.text=textread(filenameandpath,'%s');%读入txt文件数据
set(handles.edit1,'String',filenameandpath);
guidata(hObject,handles);
% --- 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)
check=inputdlg('请输入要统计的单字','输入要统计的字',1);
sizecheck=length(check{1});
lastline=size(handles.text);
wordcounter=0;
for line=1:1:lastline(1)%从第一行开始到最后一行
curline=handles.text{line};
lastword=size(curline);
for i=1:1:lastword(2)-sizecheck+1%从本行第一个字开始检索
if(strcmp(check,curline(i:i+sizecheck-1)))
wordcounter=wordcounter+1;
end
end
end
set(handles.edit2,'String',int2str(wordcounter));
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- 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)
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
lastline=size(handles.text);
wordcounter=0;
zilist=cell(10000,1);
zicount=0;
pincounter=zeros(10000,1);
h=waitbar(0,'正在计算词频,请稍等...');
pause(0.5);
for line=1:1:lastline(1)%从第一行开始到最后一行
curline=handles.text{line};
lastword=size(curline);
for i=1:1:lastword(2)%从本行第一个字开始检索
if(checkifexist(curline(i),zilist,zicount))
%表里面有
else
zicount=zicount+1;
zilist{zicount,1}=curline(i);%加入表格
end
end
str=['计算词频已完成’,int2str(line/lastline(1)*100),'%']
waitbar(line/laetline(1),h,str);
end
close(h);
xlswrite('result.xls',zilist,'sheet1','A1');
msgbox('结果已输出到result.xls,请打开查看');
我不懂这个哪里错了,如果使用strrep,我需要怎么在其中插入啊?