Plot two data sets and only clear one of them ?
1 次查看(过去 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!