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

3 vues (au cours des 30 derniers jours)
Nathaniel Sweeney
Nathaniel Sweeney le 22 Oct 2019
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

Réponses (2)

Daniel M
Daniel M le 22 Oct 2019
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 le 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

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by