【发布时间】:2016-02-24 16:24:00
【问题描述】:
我创建了一个简单的时间序列图。然后我放大。当我放大时,我想计算缩放区域 Y 数据的平均值,并将其绘制在与原始 Y 数据相同的图上。我已经尝试过以下代码,但它会删除原始 Y 数据,并且只绘制平均数据。
d = rand(1,length(t));
f = figure;ta = plot(t,d)
he = zoom;
guidata(ta,struct('d',d't',t,'axes',ta));
he.ActionPostCallback = @calcMean;
function calcMean(obj,evd)
data = guidata(obj);
newLim = evd.Axes.XLim;
tStart = round(newLim(1));
tEnd = round(newLim(2));
Croppedt = find(data.t(tStart:tEnd));
CroppedD = ones(1,length(Croppedt)).*mean(data.d(Croppedt));
plot(gca,data.t(tStart:tEnd),CroppedD,'r')
end
有什么想法吗?谢谢!
【问题讨论】: