How to change the color of the most recent plot point?

1 次查看(过去 30 天)
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

回答(2 个)

Daniel M
Daniel M 2019-10-22
Consider the following idea:
N = 10;
cmap = parula(N);
figure
for n = 1:N
plot(n,n,'o','Color',cmap(n,:))
hold on
end

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-10-22
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

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by