MATLAB Answers

# Every 1,5,9,13..... marker point should be of same color. Similarly 2,6,10...... and 3,7,11...... and 4,9,12.... should be of same color

1 view (last 30 days)
Aristo Pacino on 3 Apr 2021
Commented: Aristo Pacino on 4 Apr 2021
As shown in the plot below. I need the marker color of [1,5,9,13........] of same color. Similarly [2,6,10,.....] for e.g., green; [3,7,11......] for e.g blue; [4,9,12...] for e.g. magenta.
Thanks ,
Aristo
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

DGM on 3 Apr 2021
Edited: DGM on 3 Apr 2021
Try something like this:
len = 1000; % dataset length
x = linspace(0,10,len);
y = exp(x/10).*sin(4*x);
colors=[1 0 0; ...
0 1 0; ...
0 0 1; ...
1 1 0];
clf;
plot(x,y); hold on;
ncolors=size(colors,1);
for p=1:ncolors
plot(x,y,'o','MarkerSize',8,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',colors(p,:),...
'MarkerIndices',p:ncolors:len)
end
This requires a relatively recent version. I'm not sure of the exact version, but the 'markerindices' property isn't a thing in R2015b at least.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

Jan on 3 Apr 2021
x = 1:100;
y = rand(1, 100);
colorPool = [1,0,0; 0,1,0; 0,0,1; 1,0,1];
figure;
axes('NextPlot', 'add'); % Equivalently to: hold('on')
plot(x, y, 'b-');
for k = 1:4
ind = k:4:100;
plot(x(ind), y(ind), 'o', 'MarkerEdgeColor', colorPool(k, :));
end
##### 1 CommentShowHide None
Aristo Pacino on 4 Apr 2021
This also works! Thanks very much!!

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!