【下载说明】
1 点击上面的地址,打开下载页面
2 点击"普通下载"--等待30秒--点击"下载"按钮--保存
可以帮助你画出很平滑的图,并支持多个曲线。更多帮助信息,请运行文件,按TAB键查看。
这个程序,是我读研的时候做的。工作之后,不在接触MATLAB了,所以生疏了很多了...
function varargout=freeplot(numlines)
% 可以手动画出平滑的曲线的函数,但是最多能画7条曲线
%检查输入参数
if nargin~=1
numlines=5;%默认画5条曲线
end
if ~isreal(numlines) && length(numlines)~=1 && ...
ndims(numlines)~=2 && numlines<=0
error('输入参数必须是一个正整数!');
end
if numlines>7
error('最多可以画7条曲线!');
return;
end
%打开一个figure窗口
hFig=figure('Name','FreePlot---作者:PenG','NumberTitle','off');
%设置需要的应用程序数据
setappdata(gcf,'total_lines',numlines);%设置总的线条数
setappdata(gcf,'current_lines',1);%设置当前正在绘制的线是第几条
lines=cell(1,numlines);
setappdata(gcf,'lines',lines);%保存每条曲线所画的点
spline_lines=cell(1,numlines);
setappdata(gcf,'spline_lines',spline_lines);%保存每条曲线平滑后的点
colors={'b','g','r','c','m','y','k'};
setappdata(gcf,'colors',colors(1,1:numlines));%设置每条曲线的颜色
line_styles={'-',':','-.','--','-',':','-.'};
setappdata(gcf,'line_styles',line_styles(1,1:numlines));%设置每条曲线的线形
num_points=zeros(1,numlines);
setappdata(gcf,'num_points',num_points);%设置每条曲线的所画的点数
setappdata(gcf,'num_enters',0);%设置点击Enter键的次数
setappdata(gcf,'grid',1);%设置网格为显示
setappdata(gcf,'box',0);%设置盒子为关闭
setappdata(gcf,'xlabel',[]);%设置X轴注释为空
setappdata(gcf,'ylabel',[]);%设置Y轴注释为空
setappdata(gcf,'title',[]);%设置图形标题为空
setappdata(gcf,'axis_lim',[0 10 0 10]);%设置X轴和Y轴的范围都为0到10
setappdata(gcf,'xtick',[]);%设置X轴标签
setappdata(gcf,'ytick',[]);%设置Y轴标签
setappdata(gcf,'istick',0);%标志是否设置标签
setappdata(gcf,'islegend',0);%标志是否设置legend
setappdata(gcf,'legend',[]);%曲线legend
%对figure窗口做其他的设置
axis_lim=getappdata(gcf,'axis_lim');
axis(axis_lim);
set(gcf,'WindowButtonMotionFcn',{@mouse_moveFcn,1});
set(gcf,'WindowButtonDownFcn',{@mouse_downFcn,1});
set(gcf,'KeyPressFcn',{@key_pressFcn});
set(gcf,'Pointer','crosshair');
grid on
set(gca,'Color','white');
hold on
%鼠标移动时都会执行的函数
function mouse_moveFcn(obj,evt,flag)
if flag==1
pt=get(gca,'CurrentPoint');
x=pt(1,1);
y=pt(1,2);
xlim=get(gca,'XLim');
ylim=get(gca,'YLim');
if x>= xlim(1) && x<=xlim(2) && y>=ylim(1) && y<=ylim(2)
%如果鼠标在坐标轴内部
title(['Current Point: (' num2str(x) ',' num2str(y) ')']);
else
%如果鼠标在坐标轴外部
str={'按TAB键来获得帮助信息'};
title(str);