如何在matlab中绘制特定的点?

时间:2023-02-09 14:48:43

I've X axis with values [2,6,10] and for Y axis [0.5,0.4,0.2,0.2,....0.5], all values between 0 and 1.

我跟值X轴(2、6、10)和Y轴(0.5,0.4,0.2,0.2,0.5 ....],所有的值在0和1之间。

There are certain points which correspond to 2, let's say 1/3rd and the remaining 1/3rd for 6 and remaining 1/3rd for 10. The points corresponding to 2 can have any values between 0 and 1, same applies for point 6 and point 10. How can I plot this?

有一些点对应于2,假设1/3 6剩下1/3 10剩下1/3。2对应的点可以有0到1之间的任何值,同样适用于点6和点10。我怎么画出来?

3 个解决方案

#1


3  

I guess you have some way to match up each Y-value to its corresponding X-value. By generating a vector of the same length as Y with these X-values they can then be plotted against each other.

我猜你有办法把每个y值和它对应的x值匹配起来。通过用这些x值生成与Y相同长度的向量,它们就可以被绘制成相互对立的图。

The two vectors will then have the following form:

这两个向量将会有以下形式:

X = [2,6,2,10,6,6,10,2,....6]
Y = [0.5,0.4,0.2,0.2,0.9,0.3....0.5]

Here is a sample code

这是一个示例代码

% X-data
X = [2,6,10];

% Generate random Y-data
n1 = 10;
n2 = 20;
n3 = 30;
n = n1 + n2 + n3;
Y = rand(1,n);

% Match X indices corresponding to Y
% Xall = [2,2,2,...,2,6,6,6,...,6,10,10,10,...,10]
X1 = zeros(1,n1);
X1(:) = X(1);
X2 = zeros(1,n2);
X2(:) = X(2);
X3 = zeros(1,n3);
X3(:) = X(3);
Xall = [X1 X2 X3];

plot(Xall,Y,'o')
xlim([min(X)-2,max(X)+2])

which will generate a figure of the following form

哪个将生成以下表单的图形

如何在matlab中绘制特定的点?

#2


2  

plot(a(1:3:end))

This will plot every third point.

这是每三分之一。

#3


1  

a=[0.5,0.4,0.2,0.2,....0.5]
b=[1:3:length(a)]

plot(a(b))

#1


3  

I guess you have some way to match up each Y-value to its corresponding X-value. By generating a vector of the same length as Y with these X-values they can then be plotted against each other.

我猜你有办法把每个y值和它对应的x值匹配起来。通过用这些x值生成与Y相同长度的向量,它们就可以被绘制成相互对立的图。

The two vectors will then have the following form:

这两个向量将会有以下形式:

X = [2,6,2,10,6,6,10,2,....6]
Y = [0.5,0.4,0.2,0.2,0.9,0.3....0.5]

Here is a sample code

这是一个示例代码

% X-data
X = [2,6,10];

% Generate random Y-data
n1 = 10;
n2 = 20;
n3 = 30;
n = n1 + n2 + n3;
Y = rand(1,n);

% Match X indices corresponding to Y
% Xall = [2,2,2,...,2,6,6,6,...,6,10,10,10,...,10]
X1 = zeros(1,n1);
X1(:) = X(1);
X2 = zeros(1,n2);
X2(:) = X(2);
X3 = zeros(1,n3);
X3(:) = X(3);
Xall = [X1 X2 X3];

plot(Xall,Y,'o')
xlim([min(X)-2,max(X)+2])

which will generate a figure of the following form

哪个将生成以下表单的图形

如何在matlab中绘制特定的点?

#2


2  

plot(a(1:3:end))

This will plot every third point.

这是每三分之一。

#3


1  

a=[0.5,0.4,0.2,0.2,....0.5]
b=[1:3:length(a)]

plot(a(b))