plot by skipping some points

125 views (last 30 days)
Babu Sankhi
Babu Sankhi on 1 Feb 2021
Commented: Babu Sankhi on 3 Feb 2021
Hi all,
I want to plot by skipping some points (4,31), (8, 71) and so on in my data . Is there any straight forward way of doing it?
Thank you
x=[1:1:20];
y=[1:10:200];
%x=c(:,1)
plot (x,y,'o');
%ismembertol(
  2 Comments
Babu Sankhi
Babu Sankhi on 2 Feb 2021
I am sorry about that I just want to plot by skipping some coordinates.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 1 Feb 2021
Edited: Adam Danz on 2 Feb 2021
Several methods to plot a subset of values within an array.
  1. Indexing. If you want to eliminate a list of (x,y) values, use functions like ismember, ismembertol, or == to create an index of matches, idx. Then use ~idx to select all other values when plotting plot(x(~idx), y(~idx)).
  2. Nan-replacement. After finding the values you want to ignore using indexing, replace those values with NaN. x(idx)=NaN; y(idx)=NaN; plot(x,y)
  3. Remove unwanted values. After finding the values you want to ignore using indexing, remove them using x(idx)=[]; y(idx)=[]; plot(x,y)
  4. To plot every n'th value: plot(x(1:n:end), y(1:n:end));
  5. To remove every n'th value: x(1:n:end)=[]; y(1:n:end)=[]; plot(x,y)
  6. To plot the n'th, m'th, and p'th values: idx=[n,m,p]; plot(x(idx),y(idx));
  7. To eliminate the n'th, m'th, and p'th values: idx=[n,m,p]; x(idx)=[]; y(idx)=[]; plot(x,y)
If you need additional help implementing any of those ideas, show us what you've tried where you're stuck.
  3 Comments
Babu Sankhi
Babu Sankhi on 3 Feb 2021
Thanks for your elaborative ideas.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by