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

12 次查看(过去 30 天)
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?

采纳的回答

Cameron
Cameron 2023-2-13
编辑:Cameron 2023-2-14
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 个评论
Cameron
Cameron 2023-2-14
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by