clc;clear
n = 200;
x = (1:1:n)';
y = randi([600,6000],n,1)+10*x.^1.05;
color = ['r';'b';'g';'k';'c'];
shape = ['.';'o';'*';'s';'p'];
m = [7;10;15;30;60];
clen = cell(size(m,1),1);
for i = 1:1:size(m,1)
mday(x,y,m(i),[color(i),'-',shape(i)]);
clen{i,1} = [num2str(m(i)),'日线'];
hold on
end
legend(clen)
box off
grid on
xlabel('天数');
ylabel('均价');
函数
function ymean = mday(x,y,m,color)
n = size(x,1);
ymean = zeros(n-m+1,1);
for i = m:n
ymean(i-m+1,1) = mean(y(i-m+1:1:i,1));
end
plot(x(m:1:n),ymean,color)
end