How to plot from a line array?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Andrew Boggiano
le 25 Fév 2020
Modifié(e) : Guillaume
le 25 Fév 2020
I'm indexing several lines in a line array as such:
h(i) = plot(B, sim/max(sim));% i = integer
Is there a function that is sort of the reverse of delete(h(i))?
I'm trying to add certain lines to figures together pulling from an array of several lines.
EDIT:
Basically I am looking for a way to easily replot lines that I have already plotted without having to use the plot() function and set the linewidths and colors, etc. all over again. I have found that indexing my lines in a line array has been helpful for removing certain plots by using delete(h), but I haven't found a way to re-add them onto figures after deleting.
2 commentaires
Réponse acceptée
Guillaume
le 25 Fév 2020
Modifié(e) : Guillaume
le 25 Fév 2020
Note that what you get out of plot are handles to the lines, not the line objects themselves. In normal circumstances the difference doesn't matter, but if you call delete(h) you destroy the underlying line object and you're left with a handle to an object that is no more. At this point, there's no way to restore it.
If the underlying object still exist (i.e. you haven't deleted it explictly with delete or implicitly by destroying its parent axes (e.g. with a new plot or by closing the figure), you can copy it in a new parent with copyobj.
3 commentaires
Guillaume
le 25 Fév 2020
Modifié(e) : Guillaume
le 25 Fév 2020
It's not something I'd ever tried, but it turns out that you can reparent a graphics object to an empty graphics placeholder and later reparent it to a new axes. To be honest, I was surprised it works so I'd be wary of how reliable this is:
%hlines: an array of Line objects
%eg
figure; hlines = plot(magic(3));
[hlines(1:2).Parent] = deal([]); %effectively removes the first two lines from the plot.
%can then later on be reparented
figure; hax = gca;
[hlines(1:2).Parent] = deal(hax);
Note that if you're dealing with scalar line objects, you don't need to bother with [] and deal:
%hline: a scalar object
hline.Parent = [];
hline.Parent = ax;
Plus de réponses (1)
darova
le 25 Fév 2020
Here is an example
clc,clear
% create some data with handles
h(1) = plot([0 1],[0 1],'r');
hold on
h(2) = plot([1 3],[1 2],'b');
h(3) = plot([3 4],[2 3],'g');
hold off
% save data fro h(2)
x = get(h(2),'xdata');
y = get(h(2),'ydata');
axis tight
hold on
pause(1)
delete(h(2:3))
pause(1)
plot(x,y)
hold off
Why do you need such function? Can you show your code?
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Mobile Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!