Effacer les filtres
Effacer les filtres

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

6 vues (au cours des 30 derniers jours)
Arghyadeep
Arghyadeep le 13 Fév 2023
Commenté : Cameron le 14 Fév 2023
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?

Réponse acceptée

Cameron
Cameron le 13 Fév 2023
Modifié(e) : Cameron le 14 Fév 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 commentaires
Arghyadeep
Arghyadeep le 13 Fév 2023
Ideally, I would want something like this with labels too if possible.
Cameron
Cameron le 14 Fév 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by