5

ムービーを作成する必要があります。軸を作成し、その上に非常にカスタマイズされたものをプロットするとします。

figure;
ax = plot(x, y, 'linewidth', 3, 'prop1', value1, 'prop2', value2, ...);
grid minor;
axis(ax, [xmin xmax ymin ymax]);
legend(ax, ...);
xlabel(ax, ...);
ylabel(ax, ...);
title(ax, ...);

ここで、 の値のみyが更新されるループを実行します。

for k = 1 : N
% y changes, update the axis
end

すべての軸のプロパティを保持しながら、軸を new y(またはxand ) で更新する最も速くて簡単な方法は何ですか?y

4

2 に答える 2

6

簡単な方法は、プロットしたデータの y 値を単純に更新することです。

%# note: plot returns the handle to the line, not the axes
%# ax = gca returns the handle to the axes
lineHandle = plot(x, y, 'linewidth', 3, 'prop1', value1, 'prop2', value2, ...);

%# in the loop
set(lineHandle,'ydata',newYdata)

編集複数の行がある場合、つまりlineHandleベクトルの場合はどうなりますか? ワンステップで更新できます。ただし、データをセル配列に変換する必要があります。

%# make a plot with random data
lineHandle = plot(rand(12));

%# create new data
newYdata = randn(12);
newYcell = mat2cell(newYdata,12,ones(1,12));

%# set new y-data. Make sure that there is a row in 
%# newYcell for each element in lineH (i.e. that it is a n-by-1 vector
set(lineHandle,{'ydata'},newYcell(:) );
于 2012-04-25T14:30:07.577 に答える
0

軸ハンドルを後続のプロット コマンドに戻すだけです

すなわち

plot(ax, ...)

それよりも

ax = plot(...)
于 2012-04-25T14:27:22.957 に答える