📄 concatenate.m
字号:
function varargout = concatenate(varargin)% CONCATENATE M-file for concatenate.fig% CONCATENATE, by itself, creates a new CONCATENATE or raises the existing% singleton*.%% H = CONCATENATE returns the handle to a new CONCATENATE or the handle to% the existing singleton*.%% CONCATENATE('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in CONCATENATE.M with the given input arguments.%% CONCATENATE('Property','Value',...) creates a new CONCATENATE or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before concatenate_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to concatenate_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 concatenate%作者:林骥%E-mail:linji@live.com%日期:2008年4月7日, 2008年8月31日% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @concatenate_OpeningFcn, ... 'gui_OutputFcn', @concatenate_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif 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 concatenate is made visible.function concatenate_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 concatenate (see VARARGIN)% Choose default command line output for concatenatehandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes concatenate wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = concatenate_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 structurevarargout{1} = handles.output;% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global file1name file2name file3name str0 str1 str01if isempty(file1name) || isempty(file2name) || isempty(file3name) errordlg('请先选择文件!');else test1=file1name(1,length(file1name)-3:length(file1name)); switch test1 case '.txt' h=waitbar(0,'请稍等,正在读取文件...'); %打开需要合并的第一个文件 fid0=fopen(str0,'r'); %打开想要合并到的目标文件 fid01=fopen(str01,'wt'); counter0=1; while feof(fid0)==0 %feof(fid) returns 1 if at the end-of-file and 0 otherwise string0=fgetl(fid0); %打开需要合并的第二个文件 fid1=fopen(str1,'r'); counter1=1; while feof(fid1)==0 string1=fgetl(fid1); % horizontally concatenates corresponding rows of str0, str1 fprintf(fid01, '%s\n', strcat(string0,string1)); counter1=counter1+1; end fclose(fid1); counter0=counter0+1; waitbar(counter0/(counter0+10),h,'请稍等,正在合并文件...'); end fclose(fid0); fclose(fid01); waitbar(1,h,'合并文件已完成!'); pause(0.5); close(h); case '.xls' h=waitbar(0,'请稍等,正在读取文件...'); [num0 char0]=xlsread(str0); waitbar(0.1,h,'请稍等,正在读取文件....'); [num1 char1]=xlsread(str1); waitbar(0.3,h,'请稍等,正在读取文件....'); n=length(char0); m=length(char1); for i=1:n char01(m*(i-1)+1:m*i,1)=strcat(char0(i),char1); end waitbar(0.5,h,'请稍等,正在合并文件...'); xlswrite(str01,char01,'Sheet1'); waitbar(1,h,'合并文件已完成!'); pause(0.5); close(h); otherwise errordlg('文件格式不对,请重新选择!'); endend% --- 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)close(gcf)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');endfunction 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');endfunction edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (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 edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (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 Untitled_1_Callback(hObject, eventdata, handles)% hObject handle to Untitled_1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function Untitled_3_Callback(hObject, eventdata, handles)% hObject handle to Untitled_3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --------------------------------------------------------------------function about_Callback(hObject, eventdata, handles)% hObject handle to about (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)msgbox('感谢使用!如有疑问,请联系:linji@live.com');% --------------------------------------------------------------------function quit_Callback(hObject, eventdata, handles)% hObject handle to quit (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)close(gcf);% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global file1name str0 %选择需要合并的第一个文件的路径[file1name,path1name]=uigetfile({'*.txt';'*.xls'},'选择需要合并的第一个文件');if length(file1name)<5 errordlg('未指定文件','File Error');else %合成路径+文件名 str0=[path1name file1name]; set(handles.edit1,'string',str0);end% --- Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject handle to pushbutton9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global file2name str1 %选择需要合并的第二个文件的路径[file2name,path2name]=uigetfile({'*.txt';'*.xls'},'选择需要合并的第二个文件');if length(file2name)<5 errordlg('未指定文件','File Error');else %合成路径+文件名 str1=[path2name file2name]; % fid1=fopen(str1,'r'); set(handles.edit2,'string',str1);end% --- Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global file3name str01%选择想要合并到的目标文件的路径[file3name,path3name]=uigetfile({'*.txt';'*.xls'},'选择想要合并到的目标文件');if length(file3name)<5 errordlg('未指定文件','File Error');else %合成路径+文件名 str01=[path3name file3name]; set(handles.edit3,'string',str01);end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -