How to change the color of the most recent plot point?
2 views (last 30 days)
Show older comments
I am trying to make something that will change the color of the most recent plot point.
This is my code so far:
%% Clear
clear;
close all;
clc;
%% matrix creation
b = [100,25,50,25; 50,50,50,50; 20,125,5,50; 5,10,15,170];
%% plot
times = length(b(:,1));
for k = 1 : times
R = b(k,1) + b(k,2);
L = b(k,3) + b(k,4);
T = b(k,1) + b(k,3);
B = b(k,2) + b(k,4);
sum = b(k,1) + b(k,2) + b(k,3) + b(k,4);
Rper = R/sum;
Lper = L/sum;
Tper = T/sum;
Bper = B/sum;
Hdist = 6.5;
Vdist = 4.25;
RHdist = Hdist * Rper;
LHdist = Hdist * Lper;
x = RHdist - LHdist;
TVdist = Vdist * Tper;
BVdist = Vdist * Bper;
y = TVdist - BVdist;
hold all
pause( 1 );
figure
plot(x,y,'o','MarkerFaceColor','k','MarkerEdgeColor','k')
xlim([-6.5 6.5])
ylim([-4.25 4.25])
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
grid on
end
0 Comments
Answers (2)
KALYAN ACHARJYA
on 22 Oct 2019
clear;
close all;
clc;
%% matrix creation
b = [100,25,50,25; 50,50,50,50; 20,125,5,50; 5,10,15,170];
%% plot
figure
times = length(b(:,1));
for k = 1 : times
R = b(k,1) + b(k,2);
L = b(k,3) + b(k,4);
T = b(k,1) + b(k,3);
B = b(k,2) + b(k,4);
sum = b(k,1) + b(k,2) + b(k,3) + b(k,4);
Rper = R/sum;
Lper = L/sum;
Tper = T/sum;
Bper = B/sum;
Hdist = 6.5;
Vdist = 4.25;
RHdist = Hdist * Rper;
LHdist = Hdist * Lper;
x(k)= RHdist - LHdist;
TVdist = Vdist * Tper;
BVdist = Vdist * Bper;
y(k)= TVdist - BVdist;
hold all
pause( 1 );
if k>=2
plot(x(k-1),y(k-1),'o','MarkerFaceColor','k','MarkerEdgeColor','k');
hold on;
end
plot(x(k),y(k),'o','MarkerFaceColor','r','MarkerEdgeColor','k')
xlim([-6.5 6.5])
ylim([-4.25 4.25])
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
grid on
end
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!