我正在尝试为 interp1(或抽取或重新采样)找到正确的采样率,以绘制 imfreehand 获得的轴上的多个点。
首先我绘制一些东西(任何不是正弦特定的东西)
bands=1:20;plot(bands,sin(bands));
hax=gca;
然后在轴上用 imfreehand 画一些东西,如下所示:
imfreehand('Closed',0);
我从 imfreehand 对象中提取数据部分(大小 1x413) ,然后我尝试用原始线的长度绘制它们,但缩放是错误的......
data=get(hfree);
xydata=get(data.Children(4));
% x=xydata.XData;
y=xydata.YData;
len=length(y);
x=1:len;
newlen=length(bands);
scale=(len-1)/(newlen-1);
xx=1:scale:len;
yy=interp1(x,y,xx,'spline');
line(1:length(yy),yy(1:length(yy)),...
'LineWidth',4,...
'Color',[.8 .8 .8],...
'Parent',hax);
有什么提示吗??
此外,与建议的下采样相同的结果..
for i=4:1:15 %just testing numbers
yy = downsample(y,i);
h=line(1:length(yy),yy(1:length(yy)),...
'LineWidth',1.2,...
'Color',[.8-i/100 .8-i/100 .8-i/100],...
'Parent',hax);
if length(bands)==length(yy)
set(h,'Color',[0 0 0], 'LineWidth',2);
end
end
有什么提示吗??x2