向量必须是相同长度的误差。

时间:2021-10-15 16:10:28

I've got a 250 x 250 image, I want to have a scatter plot of the intensity of every pixel and its nearest neighborhood. This is my code:

我有一个250×250的图像,我想要一个每个像素的强度和最近的邻域的散点图。这是我的代码:

I = imread(image);
i = [1,249];
j = [1,250];
X = I(i,j);
Y = I(i+1,j);
scatter(X,Y);

why do I get the " X and Y vectors must be the same length" error? They are the same length !

为什么X和Y向量的长度一定相同?它们的长度是一样的!

2 个解决方案

#1


1  

Because scatter(X, Y) is only used for vectors, not matrix. In your example, both X and Y are 2x2 matrices, not vectors.

因为散射(X, Y)只用于向量,而不是矩阵。在你的例子中,X和Y都是2x2矩阵,而不是向量。

From its documentation:

从它的文档:

scatter(X,Y) displays circles at the locations specified by the vectors X and Y. This type of graph is also known as a bubble plot.

散射(X,Y)在向量X和Y所指定的位置显示圆圈,这类图也称为气泡图。


Edit: if you want to plot matrix, use plotmatrix() instead:

编辑:如果你想绘制矩阵,使用plotmatrix()代替:

plotmatrix(X,Y)

#2


0  

Scatter(X,Y) is used only for vectors as herohuyongtao correctly mentioned. You could try to do the following:

散点(X,Y)只用于向量,正如希罗湖永涛(herohuyongtao)所正确提到的。你可以试着做以下事情:

m = 250;
X = I(m+1:end);
Y = I(1:end-m);
scatter(X,Y);

You convert your image matrix I into a vector X while ignoring the first column and in a vector Y while ignoring the last column. X(n) is thus the neighbour of Y(n) on the right side.

将图像矩阵I转换为向量X而忽略第一列和向量Y而忽略最后一列。X(n)是右边Y(n)的邻边。

I hope this helps!

我希望这可以帮助!

#1


1  

Because scatter(X, Y) is only used for vectors, not matrix. In your example, both X and Y are 2x2 matrices, not vectors.

因为散射(X, Y)只用于向量,而不是矩阵。在你的例子中,X和Y都是2x2矩阵,而不是向量。

From its documentation:

从它的文档:

scatter(X,Y) displays circles at the locations specified by the vectors X and Y. This type of graph is also known as a bubble plot.

散射(X,Y)在向量X和Y所指定的位置显示圆圈,这类图也称为气泡图。


Edit: if you want to plot matrix, use plotmatrix() instead:

编辑:如果你想绘制矩阵,使用plotmatrix()代替:

plotmatrix(X,Y)

#2


0  

Scatter(X,Y) is used only for vectors as herohuyongtao correctly mentioned. You could try to do the following:

散点(X,Y)只用于向量,正如希罗湖永涛(herohuyongtao)所正确提到的。你可以试着做以下事情:

m = 250;
X = I(m+1:end);
Y = I(1:end-m);
scatter(X,Y);

You convert your image matrix I into a vector X while ignoring the first column and in a vector Y while ignoring the last column. X(n) is thus the neighbour of Y(n) on the right side.

将图像矩阵I转换为向量X而忽略第一列和向量Y而忽略最后一列。X(n)是右边Y(n)的邻边。

I hope this helps!

我希望这可以帮助!