鼠标滚动缩放 ——此部分转载:http://www.ilovematlab.cn/thread-35476-2-1.html
function test
t=linspace(0,2*pi,7).'; r=1:10;
plot(cos(t)*r,sin(t)*r,'LineWidth',3)
% ---------------- 用鼠标滚轮缩放图像 ----------------
set(gcf,'WindowScrollWheelFcn',@wswf)
function wswf(src,cbd)
cp=get(gca,'CurrentPoint'); % 当前点
if cbd.VerticalScrollCount > 0
k=1.25; % 缩小图像(放大范围)
else
k=0.75; % 放大图像(缩小范围)
end
% 以当前点为缩放中心,缩放图像(改变范围)
axis(k*axis+(1-k)*cp([1,1,3,3]))
end
% ------------------ 用鼠标移动数据范围 -----------------
set(gcf,'WindowButtonDownFcn',@wbdf)
function wbdf(src,cbd) % 鼠标按下响应
cp=get(gca,'CurrentPoint'); % 初始位置
set(src,'Pointer','crosshair') % 指针样式
set(gcf,'WindowButtonUpFcn',@wbuf)
function wbuf(src,cbd) % 鼠标放开响应
cp=cp-get(gca,'CurrentPoint'); % -位移
xlim(xlim+cp(1));
ylim(ylim+cp(3));
set(gcf,'WindowButtonUpFcn','')
set(src,'Pointer','arrow')
end
end
end
等价于:
function test
t=linspace(0,2*pi,7).'; r=1:10;
plot(cos(t)*r,sin(t)*r,'LineWidth',3)
% ---------------- 用鼠标滚轮缩放图像 ----------------
set(gcf,'WindowScrollWheelFcn',@wswf)
% ------------------ 用鼠标移动数据范围 -----------------
set(gcf,'WindowButtonDownFcn',@wbdf)
end
function wswf(src,cbd)
cp=get(gca,'CurrentPoint'); % 当前点
if cbd.VerticalScrollCount > 0
k=1.25; % 缩小图像(放大范围)
else
k=0.75; % 放大图像(缩小范围)
end
% 以当前点为缩放中心,缩放图像(改变范围)
axis(k*axis+(1-k)*cp([1,1,3,3]))
end
function wbdf(src,cbd) % 鼠标按下响应
cp=get(gca,'CurrentPoint'); % 初始位置
set(src,'Pointer','crosshair') % 指针样式
set(gcf,'WindowButtonUpFcn',@wbuf)
end
function wbuf(src,cbd) % 鼠标放开响应
cp=cp-get(gca,'CurrentPoint'); % -位移
xlim(xlim+cp(1));
ylim(ylim+cp(3));
set(gcf,'WindowButtonUpFcn','')
set(src,'Pointer','arrow')
end
设置subplot子图间距
h1=subplot(*,*,1);
p=get(h1,'pos'); %1x4维
p(3)=P(3)+0.05; %右竖线
p(4)=p(4)+0.05; %上横线
set(h1,'pos',p);
按钮组的单选按钮值
要在按钮组的控件下写SelectionChangedFcn函数
得到此控件的tag值:
str=get(hObject,'tag')
switch str
case '单选按钮1tag'
case '单选按钮2tag'
end
进度条
h=waitbar(0,'wait...');
set(h,'doublebuffer','on');
.....
waitbar(m*n/(M-4)/(N-4),h);
...
close(h);
弹框输入值:
prompt={'聚类数'}; %—————输入需要决策的类别数,默认二类
titlee='输入期望聚类数:';
def={'2'};
answer=inputdlg(prompt,titlee,[1 40],def);
C=str2num(answer{1}); %如果有n个框输入值,则每个值用answer{n}取
常用句式:
打开文件:[a,b]=uigetfile('*','标题');path=[b a];load(path) or imrean(path);
指定显示:axes(handles.tag),若在同一坐标多次画图,可在前面加一句:cla(handles.tag);
得到任意控件的“值”:get(handles.tag,'方式')—————得到编辑框“dx'的输入值:get(handles.dx,'String')
连接多个字符为一个字符:[ ]————figure('NumberTitle','off','Name',['距离:',d,'角度:',a]);
xlabel字符大小设置:xlabel('...','FontSize',10)