Plot two data sets and only clear one of them ?
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
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,)
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!