how to delete the plotted particular coordinate from 2d graph

N=20;
area=100;
X=rand(1,N)*area;
Y=rand(1,N)*area;
XX=area/2;
YY=area/2;
plot(XX,YY,':o','LineWidth',3,'MarkerEdgeColor','k',...
'MarkerFaceColor','w','MarkerSize',20);
for i=1:N
plot(X(i),Y(i),'--o',...
'MarkerSize',10,'Color','b',...
'MarkerEdgeColor','b','MarkerFaceColor','b');
text(X(i),Y(i),num2str(i),'fontsize',15);
line([XX,X(i)],[YY,Y(i)])
hold on
end
>> XY=[X;Y]'
now i wish to delete the 10 no node delete from 2d gaph and delete the line and plotted marker from the node 10th

 Risposta accettata

I am not certain what you want to do, but if I understand correctly, I would set the 10th value to NaN.
Either:
X(10) = NaN;
Y(10) = NaN;
or:
XY=[X;Y]'
XY(10,:) = NaN;
depending on where in your code you want to do it. If you do not want the 10th node to be plotted, set the values to NaN before the plotting loop. The advantage of setting them to NaN is that it preserves the length of both vectors and of your ‘XY’ matrix, if that is important in your code.

4 Commenti

star i would to delete node after plotting not before plotting
The way you have your code plotted (in a for loop), your options are limited. Overplotting that value with the background colour of the plot window is the best I can do. It does not quite erase the plotted text value (it should), so I assume this is due to roundoff error in the colormap, since if the values were exactly the same, the ‘10’ value should no longer be visible.
Experiment with this to get the result you want:
N=20;
area=100;
X=rand(1,N)*area;
Y=rand(1,N)*area;
for i=1:N
h = plot(X(i),Y(i));
text(X(i),Y(i),num2str(i),'fontsize',10, 'HorizontalAlignment','center');
hold on
end
XY=[X;Y]';
Q1 = XY(10,:); % Get Coordinates
bc = get(gca,'Color'); % Get Plot Area Background Colour
text(XY(10,1), XY(10,2), '10', 'Color',bc, 'FontSize',10, 'FontWeight','bold', 'HorizontalAlignment','center')
I was concerned about the ‘ghost’ text resulting from my original solution, so I contacted MathWorks about it, submitting a bug report. I received a reply from Dr. Nade Sritanyaratana with an ingenious solution that genuinely merits I wish I’d thought of that! I learned something.
The code with Nade’s solution:
N=20;
area=100;
X=rand(1,N)*area;
Y=rand(1,N)*area;
for i=1:N
hp(i) = plot(X(i),Y(i));
ht(i) = text(X(i),Y(i),num2str(i),'fontsize',10);
hold on
end
XY=[X;Y]';
Q10 = XY(10,:); % Get Coordinates Of Point To Be Deleted
delete(hp(10)) % Delete Plotted Point
delete(ht(10)) % Delete Text Label
That I admit is better than mine.
With respect to your EDIT, simply expand on Nade’s solution:
for i=1:N
hp(i) = plot(X(i),Y(i),'--o',...
'MarkerSize',10,'Color','b',...
'MarkerEdgeColor','b','MarkerFaceColor','b');
ht(i) = text(X(i),Y(i),num2str(i),'fontsize',15);
hl(i) = line([XX,X(i)],[YY,Y(i)]);
hold on
end
XY=[X;Y]';
Q10 = XY(10,:); % Coordinates Of Deleted Values (Check)
delete(hp(10))
delete(ht(10))
delete(hl(10))

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graph and Network Algorithms in Centro assistenza e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by