Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I plot a discrete array of points say [x1,…xn] on the x axis in MATLAB

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?

Put even simply , I just want to plot [1,2,3,4,5] on the x axis with prominent dots.

So what I would ideally want is a prominent axis and prominent dots on it according to [x1,…,xn] and also display the labels .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is a picture enter image description here

What I have tried is

x=[1,2,3,4]
plot(x,0) or plot(x,1). But it shows just a blank graph. Can anyone help me out with this? I am an absolute noob in MATLAB.

I was expecting the line y=0 or y=1 with dots marking the points (1,0),(2,0),(3,0),(4,0) or (1,1),…,(4,1).

>Solution :

" I was expecting the line y=0 or y=1 with dots marking the points (1,0),(2,0),(3,0),(4,0) or (1,1),…,(4,1)."

The following script will do that:

hold('on')                                      % Do all plots in the same figure
axis([0,5,-0.1 1.1]);grid('on')                 % Set the axes and turn on the grid
x = 1:4                                         % x = [1 2 3 4]
plot(x,ones(size(x)),'b')                       % Line y=1
plot(x,zeros(size(x)),'b')                      % Line y=0
scatter(x,zeros(size(x)),'MarkerFaceColor','b') % Points: (1,0),(2,0),(3,0),(4,0)
scatter(x,ones(size(x)),'MarkerFaceColor','b')  % Points: (1,1),(2,1),(3,1),(4,1)

The result:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading