這裏有一個方法,如果你想保持環路:
figure,hold on %# avoid erasing the previous plots
for k = [1:3]
disp(B.colheaders{1, k});
%disp(B.data(1:79, k + 1));
startIdx = [1:10:79];
Variance = zeros(size(startIdx));
for j = startIdx
disp(j)
Variance(j==startIdx) = var(B.data(j:j+8, k))
end
%disp(V)
plot(Variance)
end
在這裏你跳過內環
figure,hold on
for k = [1:3]
disp(B.colheaders{1, k});
%disp(B.data(1:79, k + 1));
startIdx = [1:10:79];
varIdx = bsxfun(@plus,startIdx,(0:7)'); %# create array for indexing
currentData = B.data(:,k);
%# calculate variance for each column
Variance = var(currentData(varIdx),1,1);
plot(Variance)
end
過了一段時間我回到這個辦法。但它的工作。謝謝 – ELSheepO