Clear Filters
Clear Filters

How do I plot a discrete set of points say [x1,x2,...,xn] along the real line?

6 views (last 30 days)
Suppose I have a set of points [x1,x2,...,xn] then how do I plot them on the real line? . The reason I am asking is that I want to plot the eigen values of a Gaussian Orthogonal Ensemble along the x axis. So using eig(A) , I get an array of size n(lets say 10) . So I want to plot those 10 points along the x axis. That is I simply want to plot these real numbers on the x-axis. It does not matter if I plot it on say the line y=1 . Given a pen and paper , I would just draw a line and mark them with dots. How do I do this on MATLAB?

Accepted Answer

Cameron
Cameron on 13 Feb 2023
Edited: Cameron on 14 Feb 2023
A = gallery('lehmer',4); %example data
x = eig(A); %your eigenvalues
yValue = 0; %you can make this 1 or whatever you want
plot(x,yValue*ones(1,length(x)),'ko') %plot
  3 Comments
Cameron
Cameron on 14 Feb 2023
A = gallery('lehmer',4); %example data
x = eig(A); %your eigenvalues
yValue = 0; %you can make this 1 or whatever you want
plot(x,yValue*ones(1,length(x)),'k-o','MarkerFaceColor','k') %plot
idx = 1 - mod(bsxfun(@plus,(1:length(x))',1),2) == 1; %alternating ones and zeros
yloc = yValue*ones(1,length(x)); %set default value for yloc
offset = 0.2; %offset from your line
yloc(idx) = yloc(idx) + offset; %offset 1,3,5,7, etc
yloc(~idx) = yloc(~idx) - offset; %offset 2,4,6,8, etc
text(x,yloc,string(x)) %add annotation

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!