Plot two data sets and only clear one of them ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Gwendal Marrec
il 17 Mar 2022
Commentato: Gwendal Marrec
il 21 Mar 2022
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 Commenti
Risposta accettata
Voss
il 17 Mar 2022
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 Commenti
Più risposte (1)
Adam Danz
il 17 Mar 2022
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,)
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!