MATLAB Answers

0

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

Asked by Nathaniel Sweeney on 22 Oct 2019 at 3:19
Latest activity Answered by KALYAN ACHARJYA on 22 Oct 2019 at 6:16
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

Sign in to comment.

Tags

2 Answers

Answer by Daniel M
on 22 Oct 2019 at 5:05

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

Answer by KALYAN ACHARJYA on 22 Oct 2019 at 6:16

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

Sign in to comment.