在MATLAB中,如何在x轴上绘制离散点数组 [x1, … xn]?

huangapple go评论127阅读模式
英文:

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

问题

我只翻译代码部分,以下是代码的翻译:

假设我有一组点[x1,x2,...,xn],那么我如何在实数轴上绘制它们? 我提出这个问题的原因是我想在x轴上绘制高斯正交集合的特征值。所以使用eig(A),我得到一个大小为n的数组(假设为10)。所以我想在x轴上绘制这10个点。也就是说,我只想在x轴上绘制这些实数。如果我将它们绘制在y = 1上,也无妨。拿一支笔和纸,我只需画一条线,然后用点标记它们。我该如何在MATLAB中实现这一点?

更简单地说,我只想在x轴上以明显的点绘制[1,2,3,4,5]。

所以,我理想中想要的是一个明显的坐标轴,根据[x1,...,xn]以及显示标签显示明显的点。

我尝试过的是

x = [1,2,3,4]
plot(x, 0) 或 plot(x, 1)。但它只显示一个空白图。有人能帮助我吗?我在MATLAB中是一个绝对的新手。

我期望的是y = 0或y = 1的线,上面标有点(1,0),(2,0),(3,0),(4,0)或(1,1),...(4,1)。
英文:

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 .

Here is a picture 在MATLAB中,如何在x轴上绘制离散点数组 [x1, … xn]?

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).

答案1

得分: 2

"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)."

以下的脚本将实现这一目标:

hold on                     % 在同一图中绘制所有图形
axis([0,5,-0.1 1.1]);grid on % 设置坐标轴并显示网格
x = 1:4                     % x = [1 2 3 4]
plot(x,ones(size(x)),'b')   % 直线 y=1
plot(x,zeros(size(x)),'b')  % 直线 y=0
scatter(x,zeros(size(x)),'MarkerFaceColor','b') % 点: (1,0),(2,0),(3,0),(4,0)
scatter(x,ones(size(x)),'MarkerFaceColor','b')  % 点: (1,1),(2,1),(3,1),(4,1)

结果:

在MATLAB中,如何在x轴上绘制离散点数组 [x1, … xn]?

英文:

> " 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:

在MATLAB中,如何在x轴上绘制离散点数组 [x1, … xn]?

huangapple
  • 本文由 发表于 2023年2月14日 03:03:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定