Add more data and draw a line through the points

6 ビュー (過去 30 日間)
Auryn_
Auryn_ 2017 年 6 月 21 日
回答済み: Auryn_ 2017 年 6 月 21 日
Hello, I have created a function and each time it gives me a point of data. I use hold on/hold all for plotting these results and I obtain a series of points. Is there a way to join this points through a line for the final plot? Thanks in advance.
  1 件のコメント
Adam
Adam 2017 年 6 月 21 日
Stored the results of calling your function in an array and then just plot the whole array of results in one instruction afterwards.

サインインしてコメントする。

回答 (2 件)

Jan
Jan 2017 年 6 月 21 日
編集済み: Jan 2017 年 6 月 21 日
Result = zeros(1, 100);
for k = 1:100
Result(k) = rand; % or your external function
end
plot(Result)
Or if there is any good reason to create the diagram in steps:
figure;
axes;
LineH = line(1, 1);
for k = 1:100
YourSubFunction(LineH);
pause(0.02);
drawnow;
end
function YourSubFunction(LineH)
oldX = get(LineH, 'XData');
oldY = get(LineH, 'YData');
X = rand;
Y = oldY(end) + 0.5 + rand;
set(LineH, 'XData', [oldX, X], 'YData', [oldY, Y]);
end

Auryn_
Auryn_ 2017 年 6 月 21 日
Thanks!

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by