Plot two data sets and only clear one of them ?

2 ビュー (過去 30 日間)
Gwendal Marrec
Gwendal Marrec 2022 年 3 月 17 日
コメント済み: Gwendal Marrec 2022 年 3 月 21 日
Hello,
I have a code that plots two data sets on the same plot coming from two different text files using uigetfile(). To do so, I use the function plot twice (because this happens in two separate functions within my app designer).
My problem is that when I load a new text file, I am only able to clear the whole plot or to add the new data set to the existing previous two data sets, instead of just replacing one of them.
I have tried to use hold or linkdata but it doesn't work the way I intend it.
Any help would be much appreciated:)
Gwendal

採用された回答

Voss
Voss 2022 年 3 月 17 日
You can store the handle(s) to the plotted objects somewhere in your app structure, and delete them and replace them with new plotted objects as needed.
% store the first plotted line as line_1
line_1 = plot(1:10);
hold on
% store the second plotted line as line_2
line_2 = plot(2:11);
% delete line_2
delete(line_2);
% make another line_2 with different data
line_2 = plot(3:12);
line_1 and line_2 here would be stored in your app structure, and they might be created and deleted in different functions within your application.

その他の回答 (1 件)

Adam Danz
Adam Danz 2022 年 3 月 17 日
Option 1: Delete a data set and add a new data set.
Example:
hold(ax, 'on')
h1 = plot(__);
h2 = plot(__);
% replace h1
delete(h1)
h1 = plot(__);
Option 2: Replace the values of one dataset with the values of the second dataset.
Example:
hold(ax, 'on')
h1 = plot(__);
h2 = plot(__);
% replace h1 data
set(h1, 'XData', x, 'YData', y,)
  1 件のコメント
Gwendal Marrec
Gwendal Marrec 2022 年 3 月 21 日
Thank you @Adam Danz and @_, both of your answers helped me to understand where my problem was.

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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by