⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhengshi.m

📁 一个matlab的表面轮廓滤波程序
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = zhengshi(varargin)
% ZHENGSHI M-file for zhengshi.fig
%      ZHENGSHI, by itself, creates a new ZHENGSHI or raises the existing
%      singleton*.
%
%      H = ZHENGSHI returns the handle to a new ZHENGSHI or the handle to
%      the existing singleton*.
%
%      ZHENGSHI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ZHENGSHI.M with the given input arguments.
%
%      ZHENGSHI('Property','Value',...) creates a new ZHENGSHI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before zhengshi_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to zhengshi_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 zhengshi
% Last Modified by GUIDE v2.5 31-May-2006 08:52:41
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @zhengshi_OpeningFcn, ...
                   'gui_OutputFcn',  @zhengshi_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 zhengshi is made visible.
function zhengshi_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 zhengshi (see VARARGIN)
% Choose default command line output for zhengshi
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zhengshi wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = zhengshi_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 ZR.
function R_CreateFcn(hObject, eventdata, handles)
% hObject    handle to R (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 R_Callback(hObject, eventdata, handles)
% hObject    handle to R (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 R as text
%        str2double(get(hObject,'String')) returns contents of R as a
%        double
% --- Executes during object creation, after setting all properties.
function ZR_Callback(hObject, eventdata, handles)             %前期操作
 [filename,pathname] = uigetfile({'*.mat'},'Read from');      %浏览文件
fidr = fopen([pathname,filename],'r');                        %打开文件                                                                                                      %读文件
  global d;                                                   %定义全局变量
 g= fread(fidr); 
 d=[g' g(1)]';
  n=size(d,1);
k=[0:2*pi./(n-1):2*pi];
R=str2num(get(handles.R,'string'));                          %读入输入的R值
axes(handles.axes1);                                         %定义画图坐标
x=(R+d'./100).*cos(k);                                       %坐标变换
y=(R+d'./100).*sin(k);                                       %坐标变换
plot(x,y,'k')                                                    %绘制初始图
% --- Executes during object creation, after setting all properties.
function Rp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Rp (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 Rp_Callback(hObject, eventdata, handles)
% hObject    handle to Rp (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 Rp as text
%        str2double(get(hObject,'String')) returns contents of Rp as a
%        double
% --- Executes during object creation, after setting all properties.
function Wp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Wp (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 Wp_Callback(hObject, eventdata, handles)
% hObject    handle to Wp (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 Wp as text
%        str2double(get(hObject,'String')) returns contents of Wp as a
%        double
% --- Executes during object creation, after setting all properties.
function Rs_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Rs (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 Rs_Callback(hObject, eventdata, handles)
% hObject    handle to Rs (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 Rs as text
%        str2double(get(hObject,'String')) returns contents of Rs as a
%        double
% --- Executes during object creation, after setting all properties.
function Ws_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Ws (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 Ws_Callback(hObject, eventdata, handles)
% hObject    handle to Ws (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 Ws as text
%        str2double(get(hObject,'String')) returns contents of Ws as a
%        double
% --- Executes on button press in LB.
function LB_Callback(hObject, eventdata, handles)                  %滤波操作
% hObject    handle to LB (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global d;
n=size(d,1)+1;
k=[0:2*pi./(n-1):2*pi];
Rp=str2num(get(handles.Rp,'string'));                        %通带内最大波动
Wp=str2num(get(handles.Wp,'string'));                               %通频带
Rs=str2num(get(handles.Rs,'string'));                        %阻带内最小抑制
Ws=str2num(get(handles.Ws,'string'));                               %阻频带
[n,Wn]=buttord(Wp,Ws,Rp,Rs);                      %求出滤波器的阶次和截止频率
g=get(handles.LB,'Value');                                        %滤波种类
if g==1;                                                          %低通滤波
    [s,r]=butter(n,Wn);
p=filter(s,r,d);
R=str2num(get(handles.R,'string'));
p=[p' p(1)]';
axes(handles.axes2);
x=(R+p'./100).*cos(k);
y=(R+p'./100).*sin(k);
plot(x,y,'k');
axes(handles.axes3);
plot(x,y,'k')
axes(handles.axes4);
plot(x,y,'k')
elseif g==2                                                       %高通滤波
    [s,r]=butter(n,Wn,'high');
    p=filter(s,r,d);
R=str2num(get(handles.R,'string'));
p=[p' p(1)]';
axes(handles.axes2);
x=(R+p'./100).*cos(k);
y=(R+p'./100).*sin(k);
plot(x,y,'k')
axes(handles.axes3);
plot(x,y,'k')
axes(handles.axes4);
plot(x,y,'k')
end
global  t;
t=p'/100;
% --- Executes on button press in CZ.
function CZ_Callback(hObject, eventdata, handles)
% hObject    handle to CZ (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes2);
plot( 0, 0);
axes(handles.axes3);
plot( 0, 0);
axes(handles.axes4);
plot( 0, 0);
% --- Executes on button press in QY.
function QY_Callback(hObject, eventdata, handles)          %最小区域圆法评定
% hObject    handle to QY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t;
wi=t;
n=size(wi',1);
siet=linspace(0,360-360/n,n)/180*pi;
suma=0; sumb=0;
a=2/n*sum(wi.*cos(siet));
b=2/n*sum(wi.*sin(siet));
suma=suma+a;    sumb=sumb+b;
wi=wi-a*cos(siet)-b*sin(siet);
my=1;
maxwi=max(wi);
objfun=[1 -1 0 0];  
ci_1=[-(ones(1,n))' (zeros(1,n))' -(cos(siet))'  -(sin(siet))' ] ;
ci_2=[(zeros(1,n))' (ones(1,n))' (cos(siet))'  (sin(siet))' ];
ci=[ci_1;ci_2];
size(ci);
rb_1=-wi';
rb_2=wi';
    rb=[rb_1; rb_2];
    length(rb);
    lb=[0,0,-maxwi,-maxwi]';
    mb=[1.5*maxwi,1.5*maxwi,0.2*maxwi,0.2*maxwi]';
	[xval,least_r]=linprog(objfun,ci,rb,[],[],lb,mb);
    wi=wi-xval(3,1)*cos(siet)-xval(4,1)*sin(siet);
    suma=suma+xval(3,1);    sumb=sumb+xval(4,1);
    movexy=max(abs(xval(3)),abs(xval(4)));
wc=least_r;
center=[suma sumb];
maxdia=max(wi);
mindia=min(wi);
newri=wi;
set(handles.WC1,'string',wc);
axes(handles.axes2);
hold on
R=str2num(get(handles.R,'string'));
r=min(wi)+R;
x=r.*cos(siet);
y=r.*sin(siet);
plot(x,y,'r')
l=max(wi)+R;
x=l.*cos(siet);
y=l.*sin(siet);
plot(x,y,'r')
hold off
% --- Executes on button press in EC.
function EC_Callback(hObject, eventdata, handles)          %最小二乘圆法评定
% hObject    handle to EC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global t;
wi=t;
n=size(wi',1);
siet=linspace(0,360-360/n,n)/180*pi;
suma=0; sumb=0;
a=2/n*sum(wi.*cos(siet));
b=2/n*sum(wi.*sin(siet));
suma=suma+a;    sumb=sumb+b;
wi=wi-a*cos(siet)-b*sin(siet);
wc=max(wi)-min(wi);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -