How to add more data and plot lines to existing plot

72 ビュー (過去 30 日間)
Mukesh
Mukesh 2012 年 12 月 27 日
コメント済み: Image Analyst 2022 年 7 月 28 日
I am trying to add a new line to existing plot using "Add Data" in the plot browser. Instead of adding a new line (and a new variable in the plot browser) my old plot line is being replaced.
I was trying to follow the example as shown in the tutorial "second order systems with various damping coefficients". Instead of adding a new plot for T vs ampdecay my old line of t vs x was being replaced.
  2 件のコメント
Bhimappa
Bhimappa 2022 年 7 月 28 日
Add the title "sample mass" to the existing plot
Image Analyst
Image Analyst 2022 年 7 月 28 日
@Bhimappa, why should he do that? Anyway, he most likely won't since his question is 10 years old.

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

回答 (3 件)

Image Analyst
Image Analyst 2012 年 12 月 27 日
Use
hold on;
after your first call to plot() to avoid subsequent calls to plot replacing your earlier plot curves.
The hold function controls whether MATLAB clearsthe current graph when you make subsequent calls to plotting functions(the default), or adds a new graph to the current graph.
hold on retains the currentgraph and adds another graph to it. MATLAB adjusts the axes limits,tick marks, and tick labels as necessary to display the full rangeof the added graph.
hold off resets hold stateto the default behavior, in which MATLAB clears the existinggraph and resets axes properties to their defaults before drawingnew plots.
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 28 日
I don't think it's good idea to use hold on to do the same plot, I think it's better to replot new data and old data at the same time. You can't for example use get(gco,'Ydata') to get Y data.
Jan
Jan 2012 年 12 月 28 日
@Azzi: Why do you think that re-drawing is a benefit? The result of adding a new plot is exactly the same, but redarwing all lines takes more time and riquire all lines to have the same number and position of X-values. Therefore I prefer "hold on" or "hold all" .

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


Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 27 日
Add your data to your old variables then plot a new curve

Norma
Norma 2020 年 7 月 26 日
編集済み: Image Analyst 2020 年 7 月 27 日

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by