How to remove markers in plot at specified places?

조회 수: 31 (최근 30일)
Ganesh kumar Badri narayan
Ganesh kumar Badri narayan 2018년 1월 21일
댓글: Les Beckham 2018년 1월 28일
I have a 2d plot as shown in attached image, I would like to remove the middle nine marker points in this plot. How can I achieve this? Please provide your suggestion. Thank you all.
clear
clc
nx=5;
ny=5;
x=linspace(0,1,nx);
y=linspace(0,1,ny);
[X,Y]=meshgrid(x,y);
x1=linspace(1/4,1/1.33333,nx);
y1=linspace(1/4,1/1.33333,ny);
[X1,Y1]=meshgrid(x1,y1);
hold on
plot(X,Y,'k',Y,X,'k');
plot(X,Y,'ro',Y,X,'ro','MarkerFaceColor',[1,0.6,0.6]);
plot(X1,Y1,'k',Y1,X1,'k');
axis square
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 1월 21일
Which MATLAB release? The ability to adjust this easily is relatively new.
Ganesh kumar Badri narayan
Ganesh kumar Badri narayan 2018년 1월 22일
This was done in MATLAB v2017b

댓글을 달려면 로그인하십시오.

채택된 답변

Les Beckham
Les Beckham 2018년 1월 22일
If the goal is to remove all of the markers except for the 'outer' ones, then try this. This should be relatively generic (independent of the size specified by nx and ny), if not elegant.
Replace this line:
plot(X,Y,'ro',Y,X,'ro','MarkerFaceColor',[1,0.6,0.6]);
with these two lines:
Youter(2:end-1,2:end-1)=NaN;
plot(X, Youter, 'ro', 'MarkerFaceColor', [1, 0.6, 0.6])
If I misinterpreted your goals, post a comment making them more clear.
  댓글 수: 4
Ganesh kumar Badri narayan
Ganesh kumar Badri narayan 2018년 1월 22일
My bad I forgot to change the name. It works perfect. Thank you very much.
Les Beckham
Les Beckham 2018년 1월 28일
You are quite welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 22일
With recent MATLAB, you can set the MarkerIndices property of line objects; see https://www.mathworks.com/help/matlab/creating_plots/create-line-plot-with-markers.html#bvcbmlx-1
You are plotting an array of Y so one line object would be generated for each column. Record the output of plot() in order to get those handles. Leave the first and last of the handles alone and set the others to have only 1 and their length in MarkerIndices property.

Community Treasure Hunt

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

Start Hunting!

Translated by