| 查看: 2131 | 回復(fù): 13 | ||
望月任新蟲 (小有名氣)
|
[求助]
matlab gui求助 已有2人參與
|
|
如何創(chuàng)建一個按鈕調(diào)用M文件,并將顯示在顯示在一個文本框中,如圖點擊那個瀏覽按鈕所示。謝謝大家 2YKN`C86P@ZR]7}V5BXS]WO.png YAO(R~RDP([420[T0B8$0]A.png ]O[26OH(QL7YKRV[4K~R5%C.png |
木蟲 (著名寫手)

新蟲 (小有名氣)
金蟲 (小有名氣)
新蟲 (小有名氣)
金蟲 (小有名氣)
新蟲 (小有名氣)
|
function varargout = DemoGUI(varargin) % DEMOGUI M-file for DemoGUI.fig % DEMOGUI, by itself, creates a new DEMOGUI or raises the existing % singleton*. % % H = DEMOGUI returns the handle to a new DEMOGUI or the handle to % the existing singleton*. % % DEMOGUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DEMOGUI.M with the given input arguments. % % DEMOGUI('Property','Value',...) creates a new DEMOGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before DemoGUI_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to DemoGUI_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 DemoGUI % Last Modified by GUIDE v2.5 16-Apr-2005 18:42:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @DemoGUI_OpeningFcn, ... 'gui_OutputFcn', @DemoGUI_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && isstr(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 DemoGUI is made visible. function DemoGUI_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 DemoGUI (see VARARGIN) % Choose default command line output for DemoGUI handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes DemoGUI wait for user response (see UIRESUME) % uiwait(handles.DemoFig); % 日期時間顯示 set(handles.timestr,'string',datestr(now,0)); htimer = timer('StartDelay',1,'TimerFcn',... 'htimestr=findall(0,''tag'',''timestr'');set(htimestr,''string'',datestr(now,0));',... 'Period',1,'ExecutionMode','fixedSpacing','tag','showtime'); start(htimer); set(hObject,'doublebuffer','on'); % --- Outputs from this function are returned to the command line. function varargout = DemoGUI_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 ExitBtn. function ExitBtn_Callback(hObject, eventdata, handles) % hObject handle to ExitBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) selection = questdlg(['退出 ' get(handles.DemoFig,'Name') '?'],... ['退出 ' get(handles.DemoFig,'Name') '...'],... '是','否','是'); if strcmp(selection,'否') return; end htimer = timerfind('tag','showtime'); stop(htimer); delete(htimer); delete(handles.DemoFig); % --- Executes on button press in HelpBtn. function HelpBtn_Callback(hObject, eventdata, handles) % hObject handle to HelpBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % str={'對不起,目前尚未完成說明文件';' 打算盡快完善整個系統(tǒng)功能及其使用說明'}; % msgbox(str,'使用幫助','help','non-modal'); !CNCHelp.CHM % 精插補按鈕回調(diào)函數(shù) % --- Executes on button press in JinBtn. function JinBtn_Callback(hObject, eventdata, handles) % hObject handle to JinBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 獲取設(shè)置的參數(shù)值 theta0 = get(handles.startRad,'UserData'); % 外輪廓起始點極角 thetat = get(handles.endRad,'UserData'); % 外輪廓中止點極角 interpTime = get(handles.interpT,'UserData'); % 插補周期 ms mihuaNum = get(handles.miHuaNum,'UserData'); % 密化點數(shù) jinjiV = get(handles.jinjiV,'UserData'); % 進給速度 mm/min jinjiV = jinjiV/60; % 進給速度mm/sec clrjinline = get(handles.clrJin,'BackgroundColor'); % 精插值點線顏色 % 獲取外輪廓函數(shù)名 filename = get(handles.SelectFcnBtn,'UserData'); if isempty(filename) msgbox('沒有選取輪廓函數(shù)!','操作錯誤'); return; end [pathstr,fcnname] = fileparts(filename); %獲得文件名與路徑名 % 判斷是順圓還是逆圓插補,實現(xiàn)不管順圓還是逆圓都可用(不過只測試了順圓--逆時針插補) if theta0>thetat % 逆圓 flag = -1; else % 順圓 flag = 1; end set(gcf,'doublebuffer','on'); axis(handles.axes2); % 設(shè)置axes2為當前坐標軸 hjinline = line('color',clrjinline,'marker','.','markersize',4,... 'visible','off', 'tag','jinline'); % 創(chuàng)建粗插值線對象 culinedata = getappdata(handles.CuBtn,'culinedata'); % 獲取粗插補線數(shù)據(jù) cutheta = culinedata(:,1); % 極角 curho = culinedata(:,2); % 極徑 numCu = length(culinedata); % 粗插補點數(shù) theta = []; r = []; set(hjinline,'visible','on'); outflag = 0; % hbar = waitbar(0,'Please wait...','name','精插補進行中'); for k = 1:numCu-1 % 對每段粗插補情況 tmptheta = cutheta(k); % theta0 rr0 = curho(k); % rho0 theta = [theta tmptheta]; r = [r rr0]; [xd,yd] = pol2cart(theta,r); % 極坐標變成平面直角坐標 set(hjinline,'xdata',xd,'ydata',yd); for n = 2:mihuaNum % 計算每段粗插補中密化點坐標 drda = drdtheta(fcnname,tmptheta); % 計算該點的數(shù)值微分 deletatheta = interpTime/1000*jinjiV/(drda^2+rr0^2)^(0.5); % 計算deltatheta tmptheta = flag*deletatheta+tmptheta; % 迭代求取下一個極角 if flag*tmptheta>flag*cutheta(end) % 對于最后一段的特殊處理,因為最后一段可能比以前的短 tmptheta = cutheta(end); % 是不能夠插入num個密化點的 outflag = 1; end rr0 = feval(fcnname,tmptheta); theta = [theta tmptheta]; r = [r rr0]; [xd,yd] = pol2cart(theta,r); set(hjinline,'xdata',xd,'ydata',yd); if outflag==1 break; % 最后一段特殊處理時跳出循環(huán) end end % waitbar(k/(numCu-1),hbar); end % close(hbar); theta = [theta cutheta(end)]; r = [r curho(end)]; jinlinedata = [theta( r( ];setappdata(hObject,'jinlinedata',jinlinedata); % 保存精插補線數(shù)據(jù)到句柄中 set(handles.chkJin,'enable','on'); % 使得顯示隱藏線復(fù)選框可用 chkLegend_Callback(handles.chkLegend,[], handles); % 粗插補按鈕回調(diào)函數(shù) % --- Executes on button press in CuBtn. function CuBtn_Callback(hObject, eventdata, handles) % hObject handle to CuBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 獲取設(shè)置的參數(shù)值 theta0 = get(handles.startRad,'UserData'); % 外輪廓起始點極角 thetat = get(handles.endRad,'UserData'); % 外輪廓中止點極角 interpTime = get(handles.interpT,'UserData'); % 插補周期 ms jinjiV = get(handles.jinjiV,'UserData'); % 進給速度 mm/min jinjiV = jinjiV/60; % 進給速度mm/sec clrlunline = get(handles.clrLun,'BackgroundColor'); % 輪廓線顏色 clrculine = get(handles.clrCu,'BackgroundColor'); % 粗插值點線顏色 % 獲取外輪廓函數(shù)名 filename = get(handles.SelectFcnBtn,'UserData'); if isempty(filename) msgbox('沒有選取輪廓函數(shù)!','操作錯誤'); return; end [pathstr,fcnname] = fileparts(filename); addpath(pathstr,'-begin'); % 將外輪廓函數(shù)所在路徑加入matlab路徑中 set(handles.chklun,'enable','on'); % 使復(fù)選框可用 set(handles.chkLegend,'enable','on'); % 使復(fù)選框可用 set(handles.chkCu,'enable','on'); % 使復(fù)選框可用 % 繪制外輪廓線 theta = linspace(theta0,thetat,1000); r = feval(fcnname,theta); % 計算外輪廓 if length(r)~=length(theta) % 通常是由于外輪廓函數(shù)不對造成 msgbox('外輪廓函數(shù)錯誤','出錯了...'); return; end axis(handles.axes2); hlunline = polar(theta,r); set(hlunline,'color',clrlunline,'tag','lunline'); % 設(shè)置tag以后好用 lundata = [theta( r( ];setappdata(hObject,'lundata',lundata); % 保存輪廓線數(shù)據(jù)到句柄中 hold on; hculine = line('color',clrculine,'marker','.','markersize',10,... 'tag','culine'); % 粗插值線對象 'erasemode','xor', hold off; theta = []; r = []; % 判斷是順圓還是逆圓插補,實現(xiàn)不管順圓還是逆圓都可用(不過只測試了順圓--逆時針插補) if theta0>thetat % 逆圓 flag = -1; else % 順圓 flag = 1; end tmptheta = theta0; while flag*tmptheta<flag*thetat % 終止判斷,考慮了順圓與逆圓 rr0 = feval(fcnname,tmptheta); % 計算外輪廓該極角出的極徑 theta = [theta tmptheta]; r = [r rr0]; [xd,yd] = pol2cart(theta,r); % 轉(zhuǎn)換為直角坐標系數(shù)值 set(hculine,'xdata',xd,'ydata',yd); % 更新插值點 drda = drdtheta(fcnname,tmptheta); % 計算該極角處數(shù)值微分 deletatheta = interpTime/1000*jinjiV/(drda^2+rr0^2)^(0.5); tmptheta = flag*deletatheta+tmptheta; % 迭代求取下一個點極角 end rr0 = feval(fcnname,thetat); % 終點加入 theta = [theta thetat]; r = [r rr0]; culinedata = [theta( r( ];setappdata(hObject,'culinedata',culinedata); % 保存粗插補線數(shù)據(jù)到句柄中 set(handles.ExportDataBtn,'enable','on'); set(handles.JinBtn,'enable','on'); chkLegend_Callback(handles.chkLegend,[], handles); % 調(diào)用圖例復(fù)選框的回掉函數(shù) % --- Executes during object creation, after setting all properties. function FcnName_CreateFcn(hObject, eventdata, handles) % hObject handle to FcnName (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in SelectFcnBtn. function SelectFcnBtn_Callback(hObject, eventdata, handles) % hObject handle to SelectFcnBtn (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('*.m', '選取外輪廓線M文件'); if filename~=0 set(handles.FcnName,'string',filename); set(hObject,'UserData',[pathname filename]); set(handles.JinBtn,'enable','off'); set(handles.ExportDataBtn,'enable','off'); set(handles.chklun,'enable','off'); set(handles.chkCu,'enable','off'); set(handles.chkJin,'enable','off'); set(handles.chkLegend,'value',0,'enable','off'); axis(handles.axes2); cla chkLegend_Callback(handles.chkLegend,[], handles); % 更新圖列 else set(handles.FcnName,'string','尚未選取'); end % --- Executes on button press in ExportDataBtn. function ExportDataBtn_Callback(hObject, eventdata, handles) % hObject handle to ExportDataBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % str={'對不起,目前尚未完成說明文件';' 打算盡快完善整個系統(tǒng)功能及其使用說明'}; % msgbox(str,'使用幫助','help','non-modal'); type = get(handles.dataType,'UserData'); % 獲取設(shè)置的導(dǎo)出數(shù)據(jù)格式 1-mat,2-txt,3-dat % % 獲取各種圖線的句柄 % hjinline = findobj(0,'tag','jinline'); % hculine = findobj(0,'tag','culine'); % hlunline = findobj(0,'tag','lunline'); % 保存時 % % handles.CuBtn % setappdata(hObject,'culinedata',culinedata); % 保存粗插補線數(shù)據(jù)到句柄中 % setappdata(hObject,'lundata',lundata); % 保存輪廓線數(shù)據(jù)到句柄中 % % handles.JinBtn % setappdata(hObject,'jinlinedata',jinlinedata); % 保存精插補線數(shù)據(jù)到句柄中 lundata = getappdata(handles.CuBtn,'lundata'); culinedata = getappdata(handles.CuBtn,'culinedata'); jinlinedata = getappdata(handles.JinBtn,'jinlinedata'); switch type case 1, [filename, pathname] = uiputfile('*.mat', '保存插補結(jié)果'); if filename==0 % 取消 return; end save([pathname filename],'lundata','culinedata','jinlinedata'); case 2, [filename, pathname] = uiputfile('*.txt', '保存插補結(jié)果'); if filename==0 return; end [pathstr,filename]=fileparts(filename); fid = fopen([pathname filename,'.txt'],'w'); fprintf(fid,'\n%=================%s=================\r\n',datestr(now,0)); fprintf(fid,'%原始外輪廓線數(shù)據(jù)\r\n'); fprintf(fid,'% 極角 \t 極徑\r\n'); fprintf(fid,'%8.6f \t %8.6f\r\n',lundata'); fprintf(fid,'%粗插補點數(shù)據(jù)\r\n'); fprintf(fid,'% 極角 \t 極徑\r\n'); fprintf(fid,'%8.6f \t %8.6f\r\n',culinedata'); fprintf(fid,'%精插補點數(shù)據(jù)\r\n'); fprintf(fid,'% 極角 \t 極徑\r\n'); fprintf(fid,'%8.6f \t %8.6f\r\n',jinlinedata'); fclose(fid); case 3, [filename, pathname] = uiputfile('*.dat', '保存插補結(jié)果'); if filename==0 return; end [pathstr,filename]=fileparts(filename); save([pathname filename,'.dat'],'lundata','culinedata','jinlinedata','-ascii','-double'); otherwise, msgbox('照道理是不會出現(xiàn)的~'); end % --- Executes on button press in ResetBtn. function ResetBtn_Callback(hObject, eventdata, handles) % hObject handle to ResetBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 設(shè)置各種參數(shù)為默認值 set(handles.startRad,'string','0','UserData',0); set(handles.endRad,'string','2*pi','UserData',2*pi); set(handles.miHuaNum,'string','4','UserData',4); set(handles.interpT,'string','8','UserData',8); set(handles.jinjiV,'string','4000','UserData',4000); set(handles.clrLun,'BackgroundColor',[0 0 0]); set(handles.clrCu,'BackgroundColor',[0 0 1]); set(handles.clrJin,'BackgroundColor',[1 1 0.5]); set(handles.dataType,'value',1,'UserData',1); set(handles.chkLegend,'value',0,'UserData',0); % --- Executes during object creation, after setting all properties. function startRad_CreateFcn(hObject, eventdata, handles) % hObject handle to startRad (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function startRad_Callback(hObject, eventdata, handles) % hObject handle to startRad (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 startRad as text % str2double(get(hObject,'String')) returns contents of startRad as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function endRad_CreateFcn(hObject, eventdata, handles) % hObject handle to endRad (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function endRad_Callback(hObject, eventdata, handles) % hObject handle to endRad (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 endRad as text % str2double(get(hObject,'String')) returns contents of endRad as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function miHuaNum_CreateFcn(hObject, eventdata, handles) % hObject handle to miHuaNum (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function miHuaNum_Callback(hObject, eventdata, handles) % hObject handle to miHuaNum (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 miHuaNum as text % str2double(get(hObject,'String')) returns contents of miHuaNum as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function interpT_CreateFcn(hObject, eventdata, handles) % hObject handle to interpT (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function interpT_Callback(hObject, eventdata, handles) % hObject handle to interpT (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 interpT as text % str2double(get(hObject,'String')) returns contents of interpT as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function jinjiV_CreateFcn(hObject, eventdata, handles) % hObject handle to jinjiV (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function jinjiV_Callback(hObject, eventdata, handles) % hObject handle to jinjiV (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 jinjiV as text % str2double(get(hObject,'String')) returns contents of jinjiV as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function dataType_CreateFcn(hObject, eventdata, handles) % hObject handle to dataType (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in dataType. function dataType_Callback(hObject, eventdata, handles) % hObject handle to dataType (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns dataType contents as cell array % contents{get(hObject,'Value')} returns selected item from dataType % 1 - mat; 2 - txt ; 3 - dat datatype = get(hObject,'Value'); set(hObject,'UserData',datatype); % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over clrLun. function clrLun_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to clrLun (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 顏色設(shè)置處理 color = uisetcolor; if length(color)~=1 % 如果選取了顏色 set(hObject,'BackgroundColor',color); hlunline = findobj(0,'tag','lunline'); if ~isempty(hlunline) % 如果已繪制圖線,則按照設(shè)置的顏色更新圖線 set(hlunline,'color',color); end end % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over clrJin. function clrJin_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to clrJin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) color = uisetcolor; if length(color)~=1 set(hObject,'BackgroundColor',color); hjinline = findobj(0,'tag','jinline'); if ~isempty(hjinline) % 如果已繪制圖線,則按照設(shè)置的顏色更新圖線 set(hjinline,'color',color); end end % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over clrCu. function clrCu_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to clrCu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) color = uisetcolor; if length(color)~=1 set(hObject,'BackgroundColor',color); hculine = findobj(0,'tag','culine'); if ~isempty(hculine) % 如果已繪制圖線,則按照設(shè)置的顏色更新圖線 set(hculine,'color',color); end end % --- Executes on button press in chklun. function chklun_Callback(hObject, eventdata, handles) % hObject handle to chklun (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chklun % 圖線的顯示隱藏復(fù)選框 val = get(hObject,'Value'); hlunline = findobj(0,'tag','lunline'); if ~isempty(hlunline) % 如果已經(jīng)繪制圖線 if val==1 % 如果是選中復(fù)選框 set(hlunline,'visible','on'); % 顯示 else set(hlunline,'visible','off'); end chkLegend_Callback(handles.chkLegend,[], handles); % 更新圖列 end % --- Executes on button press in chkCu. function chkCu_Callback(hObject, eventdata, handles) % hObject handle to chkCu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chkCu val = get(hObject,'Value'); hculine = findobj(0,'tag','culine'); if ~isempty(hculine) if val==1 set(hculine,'visible','on'); else set(hculine,'visible','off'); end chkLegend_Callback(handles.chkLegend,[], handles) end % --- Executes on button press in chkJin. function chkJin_Callback(hObject, eventdata, handles) % hObject handle to chkJin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chkJin val = get(hObject,'Value'); hjinline = findobj(0,'tag','jinline'); if ~isempty(hjinline) if val==1 set(hjinline,'visible','on'); else set(hjinline,'visible','off'); end chkLegend_Callback(handles.chkLegend,[], handles) end % --- Executes on button press in chkLegend. function chkLegend_Callback(hObject, eventdata, handles) % hObject handle to chkLegend (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chkLegend % 圖例復(fù)選框的處理 val = get(hObject,'Value'); if val ==1 % 如果選中復(fù)選框 hjinline = findobj(0,'tag','jinline'); hculine = findobj(0,'tag','culine'); hlunline = findobj(0,'tag','lunline'); % 測試是否已經(jīng)繪制曲線 并且曲線是否可見 jflag = ~isempty(hjinline) & (get(handles.chkJin,'value')); cflag = ~isempty(hculine) & (get(handles.chkCu,'value')); lflag = ~isempty(hlunline) & (get(handles.chklun,'value')); warning off MATLAB eprecatedLogicalAPI % 關(guān)閉警告信息,因為lflag等是logical,用num2str有警告strflag = [num2str(lflag) num2str(cflag) num2str(jflag)]; switch strflag case '111', % 全部 legend([hlunline hculine hjinline],'外輪廓線','粗插補點','精插補點',2); % 繪制圖例 case '110' % 不顯示精插補 legend([hlunline hculine],'外輪廓線','粗插補點',2) case '101', % 不顯示粗插補 legend([hlunline hjinline],'外輪廓線','精插補點',2) case '011', % 不顯示輪廓線 legend([hculine hjinline],'粗插補點','精插補點',2) case '100', legend(hlunline,'外輪廓線',2) case '001', legend(hjinline,'精插補點',2) case '010', legend(hculine,'粗插補點',2) otherwise legend off % 圖例不顯示 end else legend off; % 圖例不顯示 end % 采用等節(jié)距五點求導(dǎo)公式的中點公式求數(shù)值微分 % 這里存在一個問題是,數(shù)值微分的時候,h到底如何選取? % 自動選取的算法是怎么樣的?如果要自動選取,速度如何? function dr = drdtheta( fcnname,theta0) % h = 0.001; theta_2 = theta0 - 2*h; theta_1 = theta0 - h; theta1 = theta0 + h; theta2 = theta0 + 2*h; theta = [theta_2 theta_1 theta1 theta2]; r = feval(fcnname,theta); dr = 1/(12*h)*(r(1) - 8*r(2) + 8*r(3) - r(4)); |
新蟲 (小有名氣)
|
function varargout = DemoGUI(varargin) % DEMOGUI M-file for DemoGUI.fig % DEMOGUI, by itself, creates a new DEMOGUI or raises the existing % singleton*. % % H = DEMOGUI returns the handle to a new DEMOGUI or the handle to % the existing singleton*. % % DEMOGUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DEMOGUI.M with the given input arguments. % % DEMOGUI('Property','Value',...) creates a new DEMOGUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before DemoGUI_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to DemoGUI_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 DemoGUI % Last Modified by GUIDE v2.5 16-Apr-2005 18:42:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @DemoGUI_OpeningFcn, ... 'gui_OutputFcn', @DemoGUI_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && isstr(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 DemoGUI is made visible. function DemoGUI_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 DemoGUI (see VARARGIN) % Choose default command line output for DemoGUI handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes DemoGUI wait for user response (see UIRESUME) % uiwait(handles.DemoFig); % 日期時間顯示 set(handles.timestr,'string',datestr(now,0)); htimer = timer('StartDelay',1,'TimerFcn',... 'htimestr=findall(0,''tag'',''timestr'');set(htimestr,''string'',datestr(now,0));',... 'Period',1,'ExecutionMode','fixedSpacing','tag','showtime'); start(htimer); set(hObject,'doublebuffer','on'); % --- Outputs from this function are returned to the command line. function varargout = DemoGUI_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 ExitBtn. function ExitBtn_Callback(hObject, eventdata, handles) % hObject handle to ExitBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) selection = questdlg(['退出 ' get(handles.DemoFig,'Name') '?'],... ['退出 ' get(handles.DemoFig,'Name') '...'],... '是','否','是'); if strcmp(selection,'否') return; end htimer = timerfind('tag','showtime'); stop(htimer); delete(htimer); delete(handles.DemoFig); % --- Executes on button press in HelpBtn. function HelpBtn_Callback(hObject, eventdata, handles) % hObject handle to HelpBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % str={'對不起,目前尚未完成說明文件';' 打算盡快完善整個系統(tǒng)功能及其使用說明'}; % msgbox(str,'使用幫助','help','non-modal'); !CNCHelp.CHM % 精插補按鈕回調(diào)函數(shù) % --- Executes on button press in JinBtn. function JinBtn_Callback(hObject, eventdata, handles) % hObject handle to JinBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 獲取設(shè)置的參數(shù)值 theta0 = get(handles.startRad,'UserData'); % 外輪廓起始點極角 thetat = get(handles.endRad,'UserData'); % 外輪廓中止點極角 interpTime = get(handles.interpT,'UserData'); % 插補周期 ms mihuaNum = get(handles.miHuaNum,'UserData'); % 密化點數(shù) jinjiV = get(handles.jinjiV,'UserData'); % 進給速度 mm/min jinjiV = jinjiV/60; % 進給速度mm/sec clrjinline = get(handles.clrJin,'BackgroundColor'); % 精插值點線顏色 % 獲取外輪廓函數(shù)名 filename = get(handles.SelectFcnBtn,'UserData'); if isempty(filename) msgbox('沒有選取輪廓函數(shù)!','操作錯誤'); return; end [pathstr,fcnname] = fileparts(filename); %獲得文件名與路徑名 % 判斷是順圓還是逆圓插補,實現(xiàn)不管順圓還是逆圓都可用(不過只測試了順圓--逆時針插補) if theta0>thetat % 逆圓 flag = -1; else % 順圓 flag = 1; end set(gcf,'doublebuffer','on'); axis(handles.axes2); % 設(shè)置axes2為當前坐標軸 hjinline = line('color',clrjinline,'marker','.','markersize',4,... 'visible','off', 'tag','jinline'); % 創(chuàng)建粗插值線對象 culinedata = getappdata(handles.CuBtn,'culinedata'); % 獲取粗插補線數(shù)據(jù) cutheta = culinedata(:,1); % 極角 curho = culinedata(:,2); % 極徑 numCu = length(culinedata); % 粗插補點數(shù) theta = []; r = []; set(hjinline,'visible','on'); outflag = 0; % hbar = waitbar(0,'Please wait...','name','精插補進行中'); for k = 1:numCu-1 % 對每段粗插補情況 tmptheta = cutheta(k); % theta0 rr0 = curho(k); % rho0 theta = [theta tmptheta]; r = [r rr0]; [xd,yd] = pol2cart(theta,r); % 極坐標變成平面直角坐標 set(hjinline,'xdata',xd,'ydata',yd); for n = 2:mihuaNum % 計算每段粗插補中密化點坐標 drda = drdtheta(fcnname,tmptheta); % 計算該點的數(shù)值微分 deletatheta = interpTime/1000*jinjiV/(drda^2+rr0^2)^(0.5); % 計算deltatheta tmptheta = flag*deletatheta+tmptheta; % 迭代求取下一個極角 if flag*tmptheta>flag*cutheta(end) % 對于最后一段的特殊處理,因為最后一段可能比以前的短 tmptheta = cutheta(end); % 是不能夠插入num個密化點的 outflag = 1; end rr0 = feval(fcnname,tmptheta); theta = [theta tmptheta]; r = [r rr0]; [xd,yd] = pol2cart(theta,r); set(hjinline,'xdata',xd,'ydata',yd); if outflag==1 break; % 最后一段特殊處理時跳出循環(huán) end end % waitbar(k/(numCu-1),hbar); end % close(hbar); theta = [theta cutheta(end)]; r = [r curho(end)]; jinlinedata = [theta( r( ];setappdata(hObject,'jinlinedata',jinlinedata); % 保存精插補線數(shù)據(jù)到句柄中 set(handles.chkJin,'enable','on'); % 使得顯示隱藏線復(fù)選框可用 chkLegend_Callback(handles.chkLegend,[], handles); % 粗插補按鈕回調(diào)函數(shù) % --- Executes on button press in CuBtn. function CuBtn_Callback(hObject, eventdata, handles) % hObject handle to CuBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 獲取設(shè)置的參數(shù)值 theta0 = get(handles.startRad,'UserData'); % 外輪廓起始點極角 thetat = get(handles.endRad,'UserData'); % 外輪廓中止點極角 interpTime = get(handles.interpT,'UserData'); % 插補周期 ms jinjiV = get(handles.jinjiV,'UserData'); % 進給速度 mm/min jinjiV = jinjiV/60; % 進給速度mm/sec clrlunline = get(handles.clrLun,'BackgroundColor'); % 輪廓線顏色 clrculine = get(handles.clrCu,'BackgroundColor'); % 粗插值點線顏色 % 獲取外輪廓函數(shù)名 filename = get(handles.SelectFcnBtn,'UserData'); if isempty(filename) msgbox('沒有選取輪廓函數(shù)!','操作錯誤'); return; end [pathstr,fcnname] = fileparts(filename); addpath(pathstr,'-begin'); % 將外輪廓函數(shù)所在路徑加入matlab路徑中 set(handles.chklun,'enable','on'); % 使復(fù)選框可用 set(handles.chkLegend,'enable','on'); % 使復(fù)選框可用 set(handles.chkCu,'enable','on'); % 使復(fù)選框可用 % 繪制外輪廓線 theta = linspace(theta0,thetat,1000); r = feval(fcnname,theta); % 計算外輪廓 if length(r)~=length(theta) % 通常是由于外輪廓函數(shù)不對造成 msgbox('外輪廓函數(shù)錯誤','出錯了...'); return; end axis(handles.axes2); hlunline = polar(theta,r); set(hlunline,'color',clrlunline,'tag','lunline'); % 設(shè)置tag以后好用 lundata = [theta( r( ];setappdata(hObject,'lundata',lundata); % 保存輪廓線數(shù)據(jù)到句柄中 hold on; hculine = line('color',clrculine,'marker','.','markersize',10,... 'tag','culine'); % 粗插值線對象 'erasemode','xor', hold off; theta = []; r = []; % 判斷是順圓還是逆圓插補,實現(xiàn)不管順圓還是逆圓都可用(不過只測試了順圓--逆時針插補) if theta0>thetat % 逆圓 flag = -1; else % 順圓 flag = 1; end tmptheta = theta0; while flag*tmptheta<flag*thetat % 終止判斷,考慮了順圓與逆圓 rr0 = feval(fcnname,tmptheta); % 計算外輪廓該極角出的極徑 theta = [theta tmptheta]; r = [r rr0]; [xd,yd] = pol2cart(theta,r); % 轉(zhuǎn)換為直角坐標系數(shù)值 set(hculine,'xdata',xd,'ydata',yd); % 更新插值點 drda = drdtheta(fcnname,tmptheta); % 計算該極角處數(shù)值微分 deletatheta = interpTime/1000*jinjiV/(drda^2+rr0^2)^(0.5); tmptheta = flag*deletatheta+tmptheta; % 迭代求取下一個點極角 end rr0 = feval(fcnname,thetat); % 終點加入 theta = [theta thetat]; r = [r rr0]; culinedata = [theta( r( ];setappdata(hObject,'culinedata',culinedata); % 保存粗插補線數(shù)據(jù)到句柄中 set(handles.ExportDataBtn,'enable','on'); set(handles.JinBtn,'enable','on'); chkLegend_Callback(handles.chkLegend,[], handles); % 調(diào)用圖例復(fù)選框的回掉函數(shù) % --- Executes during object creation, after setting all properties. function FcnName_CreateFcn(hObject, eventdata, handles) % hObject handle to FcnName (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in SelectFcnBtn. function SelectFcnBtn_Callback(hObject, eventdata, handles) % hObject handle to SelectFcnBtn (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('*.m', '選取外輪廓線M文件'); if filename~=0 set(handles.FcnName,'string',filename); set(hObject,'UserData',[pathname filename]); set(handles.JinBtn,'enable','off'); set(handles.ExportDataBtn,'enable','off'); set(handles.chklun,'enable','off'); set(handles.chkCu,'enable','off'); set(handles.chkJin,'enable','off'); set(handles.chkLegend,'value',0,'enable','off'); axis(handles.axes2); cla chkLegend_Callback(handles.chkLegend,[], handles); % 更新圖列 else set(handles.FcnName,'string','尚未選取'); end % --- Executes on button press in ExportDataBtn. function ExportDataBtn_Callback(hObject, eventdata, handles) % hObject handle to ExportDataBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % str={'對不起,目前尚未完成說明文件';' 打算盡快完善整個系統(tǒng)功能及其使用說明'}; % msgbox(str,'使用幫助','help','non-modal'); type = get(handles.dataType,'UserData'); % 獲取設(shè)置的導(dǎo)出數(shù)據(jù)格式 1-mat,2-txt,3-dat % % 獲取各種圖線的句柄 % hjinline = findobj(0,'tag','jinline'); % hculine = findobj(0,'tag','culine'); % hlunline = findobj(0,'tag','lunline'); % 保存時 % % handles.CuBtn % setappdata(hObject,'culinedata',culinedata); % 保存粗插補線數(shù)據(jù)到句柄中 % setappdata(hObject,'lundata',lundata); % 保存輪廓線數(shù)據(jù)到句柄中 % % handles.JinBtn % setappdata(hObject,'jinlinedata',jinlinedata); % 保存精插補線數(shù)據(jù)到句柄中 lundata = getappdata(handles.CuBtn,'lundata'); culinedata = getappdata(handles.CuBtn,'culinedata'); jinlinedata = getappdata(handles.JinBtn,'jinlinedata'); switch type case 1, [filename, pathname] = uiputfile('*.mat', '保存插補結(jié)果'); if filename==0 % 取消 return; end save([pathname filename],'lundata','culinedata','jinlinedata'); case 2, [filename, pathname] = uiputfile('*.txt', '保存插補結(jié)果'); if filename==0 return; end [pathstr,filename]=fileparts(filename); fid = fopen([pathname filename,'.txt'],'w'); fprintf(fid,'\n%=================%s=================\r\n',datestr(now,0)); fprintf(fid,'%原始外輪廓線數(shù)據(jù)\r\n'); fprintf(fid,'% 極角 \t 極徑\r\n'); fprintf(fid,'%8.6f \t %8.6f\r\n',lundata'); fprintf(fid,'%粗插補點數(shù)據(jù)\r\n'); fprintf(fid,'% 極角 \t 極徑\r\n'); fprintf(fid,'%8.6f \t %8.6f\r\n',culinedata'); fprintf(fid,'%精插補點數(shù)據(jù)\r\n'); fprintf(fid,'% 極角 \t 極徑\r\n'); fprintf(fid,'%8.6f \t %8.6f\r\n',jinlinedata'); fclose(fid); case 3, [filename, pathname] = uiputfile('*.dat', '保存插補結(jié)果'); if filename==0 return; end [pathstr,filename]=fileparts(filename); save([pathname filename,'.dat'],'lundata','culinedata','jinlinedata','-ascii','-double'); otherwise, msgbox('照道理是不會出現(xiàn)的~'); end % --- Executes on button press in ResetBtn. function ResetBtn_Callback(hObject, eventdata, handles) % hObject handle to ResetBtn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 設(shè)置各種參數(shù)為默認值 set(handles.startRad,'string','0','UserData',0); set(handles.endRad,'string','2*pi','UserData',2*pi); set(handles.miHuaNum,'string','4','UserData',4); set(handles.interpT,'string','8','UserData',8); set(handles.jinjiV,'string','4000','UserData',4000); set(handles.clrLun,'BackgroundColor',[0 0 0]); set(handles.clrCu,'BackgroundColor',[0 0 1]); set(handles.clrJin,'BackgroundColor',[1 1 0.5]); set(handles.dataType,'value',1,'UserData',1); set(handles.chkLegend,'value',0,'UserData',0); % --- Executes during object creation, after setting all properties. function startRad_CreateFcn(hObject, eventdata, handles) % hObject handle to startRad (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function startRad_Callback(hObject, eventdata, handles) % hObject handle to startRad (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 startRad as text % str2double(get(hObject,'String')) returns contents of startRad as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function endRad_CreateFcn(hObject, eventdata, handles) % hObject handle to endRad (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function endRad_Callback(hObject, eventdata, handles) % hObject handle to endRad (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 endRad as text % str2double(get(hObject,'String')) returns contents of endRad as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function miHuaNum_CreateFcn(hObject, eventdata, handles) % hObject handle to miHuaNum (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function miHuaNum_Callback(hObject, eventdata, handles) % hObject handle to miHuaNum (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 miHuaNum as text % str2double(get(hObject,'String')) returns contents of miHuaNum as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function interpT_CreateFcn(hObject, eventdata, handles) % hObject handle to interpT (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function interpT_Callback(hObject, eventdata, handles) % hObject handle to interpT (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 interpT as text % str2double(get(hObject,'String')) returns contents of interpT as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function jinjiV_CreateFcn(hObject, eventdata, handles) % hObject handle to jinjiV (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 set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function jinjiV_Callback(hObject, eventdata, handles) % hObject handle to jinjiV (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 jinjiV as text % str2double(get(hObject,'String')) returns contents of jinjiV as a double str = get(hObject,'string'); data = str2num(str); if isempty(data) % 輸入?yún)?shù)有效性檢測 errordlg('輸入必須為數(shù)值!','參數(shù)錯誤'); set(hObject,'BackgroundColor','r'); else set(hObject,'BackgroundColor','w'); set(hObject,'UserData',data); end % --- Executes during object creation, after setting all properties. function dataType_CreateFcn(hObject, eventdata, handles) % hObject handle to dataType (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in dataType. function dataType_Callback(hObject, eventdata, handles) % hObject handle to dataType (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns dataType contents as cell array % contents{get(hObject,'Value')} returns selected item from dataType % 1 - mat; 2 - txt ; 3 - dat datatype = get(hObject,'Value'); set(hObject,'UserData',datatype); % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over clrLun. function clrLun_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to clrLun (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % 顏色設(shè)置處理 color = uisetcolor; if length(color)~=1 % 如果選取了顏色 set(hObject,'BackgroundColor',color); hlunline = findobj(0,'tag','lunline'); if ~isempty(hlunline) % 如果已繪制圖線,則按照設(shè)置的顏色更新圖線 set(hlunline,'color',color); end end % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over clrJin. function clrJin_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to clrJin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) color = uisetcolor; if length(color)~=1 set(hObject,'BackgroundColor',color); hjinline = findobj(0,'tag','jinline'); if ~isempty(hjinline) % 如果已繪制圖線,則按照設(shè)置的顏色更新圖線 set(hjinline,'color',color); end end % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over clrCu. function clrCu_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to clrCu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) color = uisetcolor; if length(color)~=1 set(hObject,'BackgroundColor',color); hculine = findobj(0,'tag','culine'); if ~isempty(hculine) % 如果已繪制圖線,則按照設(shè)置的顏色更新圖線 set(hculine,'color',color); end end % --- Executes on button press in chklun. function chklun_Callback(hObject, eventdata, handles) % hObject handle to chklun (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chklun % 圖線的顯示隱藏復(fù)選框 val = get(hObject,'Value'); hlunline = findobj(0,'tag','lunline'); if ~isempty(hlunline) % 如果已經(jīng)繪制圖線 if val==1 % 如果是選中復(fù)選框 set(hlunline,'visible','on'); % 顯示 else set(hlunline,'visible','off'); end chkLegend_Callback(handles.chkLegend,[], handles); % 更新圖列 end % --- Executes on button press in chkCu. function chkCu_Callback(hObject, eventdata, handles) % hObject handle to chkCu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chkCu val = get(hObject,'Value'); hculine = findobj(0,'tag','culine'); if ~isempty(hculine) if val==1 set(hculine,'visible','on'); else set(hculine,'visible','off'); end chkLegend_Callback(handles.chkLegend,[], handles) end % --- Executes on button press in chkJin. function chkJin_Callback(hObject, eventdata, handles) % hObject handle to chkJin (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chkJin val = get(hObject,'Value'); hjinline = findobj(0,'tag','jinline'); if ~isempty(hjinline) if val==1 set(hjinline,'visible','on'); else set(hjinline,'visible','off'); end chkLegend_Callback(handles.chkLegend,[], handles) end % --- Executes on button press in chkLegend. function chkLegend_Callback(hObject, eventdata, handles) % hObject handle to chkLegend (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of chkLegend % 圖例復(fù)選框的處理 val = get(hObject,'Value'); if val ==1 % 如果選中復(fù)選框 hjinline = findobj(0,'tag','jinline'); hculine = findobj(0,'tag','culine'); hlunline = findobj(0,'tag','lunline'); % 測試是否已經(jīng)繪制曲線 并且曲線是否可見 jflag = ~isempty(hjinline) & (get(handles.chkJin,'value')); cflag = ~isempty(hculine) & (get(handles.chkCu,'value')); lflag = ~isempty(hlunline) & (get(handles.chklun,'value')); warning off MATLAB eprecatedLogicalAPI % 關(guān)閉警告信息,因為lflag等是logical,用num2str有警告strflag = [num2str(lflag) num2str(cflag) num2str(jflag)]; switch strflag case '111', % 全部 legend([hlunline hculine hjinline],'外輪廓線','粗插補點','精插補點',2); % 繪制圖例 case '110' % 不顯示精插補 legend([hlunline hculine],'外輪廓線','粗插補點',2) case '101', % 不顯示粗插補 legend([hlunline hjinline],'外輪廓線','精插補點',2) case '011', % 不顯示輪廓線 legend([hculine hjinline],'粗插補點','精插補點',2) case '100', legend(hlunline,'外輪廓線',2) case '001', legend(hjinline,'精插補點',2) case '010', legend(hculine,'粗插補點',2) otherwise legend off % 圖例不顯示 end else legend off; % 圖例不顯示 end % 采用等節(jié)距五點求導(dǎo)公式的中點公式求數(shù)值微分 % 這里存在一個問題是,數(shù)值微分的時候,h到底如何選? % 自動選取的算法是怎么樣的?如果要自動選取,速度如何? function dr = drdtheta( fcnname,theta0) % h = 0.001; theta_2 = theta0 - 2*h; theta_1 = theta0 - h; theta1 = theta0 + h; theta2 = theta0 + 2*h; theta = [theta_2 theta_1 theta1 theta2]; r = feval(fcnname,theta); dr = 1/(12*h)*(r(1) - 8*r(2) + 8*r(3) - r(4)); |
新蟲 (小有名氣)
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 086500 325 求調(diào)劑 +3 | 領(lǐng)帶小熊 2026-03-19 | 3/150 |
|
|---|---|---|---|---|
|
[考研] 一志愿南昌大學(xué),327分,材料與化工085600 +6 | Ncdx123456 2026-03-19 | 6/300 |
|
|
[考研] 工科材料085601 279求調(diào)劑 +7 | 困于星晨 2026-03-17 | 9/450 |
|
|
[考研] 22408 344分 求調(diào)劑 一志愿 華電計算機技術(shù) +3 | solanXXX 2026-03-20 | 3/150 |
|
|
[考研] 廣西大學(xué)家禽遺傳育種課題組2026年碩士招生(接收計算機專業(yè)調(diào)劑) +3 | 123阿標 2026-03-17 | 3/150 |
|
|
[考研] 本人考085602 化學(xué)工程 專碩 +18 | 不知道叫什么! 2026-03-15 | 20/1000 |
|
|
[考研] 296求調(diào)劑 +4 | www_q 2026-03-18 | 8/400 |
|
|
[考研] 一志愿西南交通 專碩 材料355 本科雙非 求調(diào)劑 +4 | 西南交通專材355 2026-03-19 | 4/200 |
|
|
[考研] 材料學(xué)碩318求調(diào)劑 +5 | February_Feb 2026-03-19 | 5/250 |
|
|
[考研] 0703化學(xué)調(diào)劑 +10 | 妮妮ninicgb 2026-03-15 | 14/700 |
|
|
[考研] 288求調(diào)劑,一志愿華南理工大學(xué)071005 +5 | ioodiiij 2026-03-17 | 5/250 |
|
|
[考研] 266求調(diào)劑 +5 | 陽陽哇塞 2026-03-14 | 10/500 |
|
|
[考研] 295求調(diào)劑 +3 | 一志愿京區(qū)211 2026-03-18 | 5/250 |
|
|
[考研] 一志愿西南交大,求調(diào)劑 +4 | 材化逐夢人 2026-03-18 | 4/200 |
|
|
[考研] 0703化學(xué)336分求調(diào)劑 +6 | zbzihdhd 2026-03-15 | 7/350 |
|
|
[考研] 301求調(diào)劑 +9 | yy要上岸呀 2026-03-17 | 9/450 |
|
|
[考研] 考研化學(xué)學(xué)碩調(diào)劑,一志愿985 +4 | 張vvvv 2026-03-15 | 6/300 |
|
|
[考研] 085601求調(diào)劑 +4 | Du.11 2026-03-16 | 4/200 |
|
|
[考研] 一志愿南京大學(xué),080500材料科學(xué)與工程,調(diào)劑 +4 | Jy? 2026-03-16 | 4/200 |
|
|
[考研] 機械專碩325,尋找調(diào)劑院校 +3 | y9999 2026-03-15 | 5/250 |
|