pdist2
Pairwise distance between two sets of observations
Syntax
D = pdist2(X,Y)
D = pdist2(X,Y,distance)
D = pdist2(X,Y,'minkowski',P)
D = pdist2(X,Y,'mahalanobis',C)
D = pdist2(X,Y)
returns a matrix D
containing the Euclidean distances between each pair of observations in the mx-by-n data matrix X
and my-by-n data matrix Y
. Rows of X
and Y
correspond to observations, columns correspond to variables. D
is an mx-by-my matrix, with the (i,j) entry equal to distance between observation i in X
and observation j in Y
. The (i,j) entry will be NaN
if observation i in X
or observation j in Y
contain NaN
s.
D = pdist2(X,Y,distance)
computes D
using distance
. Choices are:
'euclidean'
Euclidean distance (default).
min
Smallest elements in array
Description
M
= min(A
)
returns the smallest elements of A
.
-
If A
is a vector, then min(A)
returns the smallest element of A
.
-
If A
is a matrix, then min(A)
is a row vector containing the minimum value of each column.
-
If A
is a multidimensional array, then min(A)
operates along the first array dimension whose size does not equal 1
, treating the elements as vectors. The size of this dimension becomes 1
while the sizes of all other dimensions remain the same. If A
is an empty array with first dimension 0
, then min(A)
returns an empty array with the same size as A
.
pdist2
Pairwise distance between two sets of observations
Syntax
D = pdist2(X,Y,distance)
D = pdist2(X,Y,'minkowski',P)
D = pdist2(X,Y,'mahalanobis',C)
D = pdist2(X,Y)
returns a matrix D
containing the Euclidean distances between each pair of observations in the mx-by-n data matrix X
and my-by-n data matrix Y
. Rows of X
and Y
correspond to observations, columns correspond to variables. D
is an mx-by-my matrix, with the (i,j) entry equal to distance between observation i in X
and observation j in Y
. The (i,j) entry will be NaN
if observation i in X
or observation j in Y
contain NaN
s.
D = pdist2(X,Y,distance)
computes D
using distance
. Choices are:
'euclidean' | Euclidean distance (default). |
min
Smallest elements in array
Description
returns the smallest elements of M
= min(A
)A
.
-
If
A
is a vector, thenmin(A)
returns the smallest element ofA
. -
If
A
is a matrix, thenmin(A)
is a row vector containing the minimum value of each column. -
If
A
is a multidimensional array, thenmin(A)
operates along the first array dimension whose size does not equal1
, treating the elements as vectors. The size of this dimension becomes1
while the sizes of all other dimensions remain the same. IfA
is an empty array with first dimension0
, thenmin(A)
returns an empty array with the same size asA
.
isempty
Determine whether array is empty
Syntax
TF = isempty(A)
Description
TF = isempty(A)
returns logical 1 (true
) if A
is an empty array and logical 0 (false
) otherwise. An empty array has at least one dimension of size zero, for example, 0-by-0 or 0-by-5.
Examples
B = rand(2,2,2); B(:,:,:) = []; isempty(B)ans = 1
exist
Check existence of variable, function, folder, or class
Syntax
exist name
exist name kind
A = exist('name','kind
')
builtin
Checks only for built-in functions.
class
Checks only for classes.
dir
Checks only for folders.
file
Checks only for files or folders.
var
Checks only for variables.
if ~exist('plot_progress', 'var') || isempty(plot_progress)
|| means logistic OR!
centroids(:,1)
centroid =
2.4283 3.1579
5.8135 2.6336
7.1193 3.6166
centroids(:,1)
ans =
2.4283
5.8135
7.1194
>> centroids(:,2)
ans =
3.1579
2.6337
3.6167
How to select random items in X
size(X) = 100*2
randnum=randperm(length(X));
initial_centroids =X(randnum(1:5), :);
imread
Read image from graphics file
Syntax
Description
A
= imread(___,Name,Value
)
specifies format-specific options using one or more name-value pair arguments, in addition to any of the input arguments in the previous syntaxes.
[A
,map
] = imread(___)
reads the indexed image in filename
into A
and reads its associated colormap into map
. Colormap values in the image file are automatically rescaled into the range [0,1]
.
ind2rgb
Convert indexed image to RGB image
Syntax
RGB = ind2rgb(X,map)
[A
,map
] = imread(___)
reads the indexed image in filename
into A
and reads its associated colormap into map
. Colormap values in the image file are automatically rescaled into the range [0,1]
.
什么是索引图像?
图中圆圈内的就是索引图像的索引表,下面的就是其对应RGB颜色表。
图中小圆圈处的索引号是5,对应RGB颜色的第5行,所以该处RGB颜色实际是0.2902 0.0627 0.0627
索引图像的作用就是体积小,方便传输,只需要把索引表传输过去,接收方用对应的RGB颜色表还原就行。
![](https://img-blog.csdn.net/20170527162953912?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2luYXRfMzY0NTg4NzA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
RGB图像模型。
三维坐标:
原点到白色顶点的中轴线是灰度线,r、g、b三分量相等,强度可以由三分量的向量表示。
用RGB来理解色彩、深浅、明暗变化:
色彩变化: 三个坐标轴RGB最大分量顶点与黄紫青YMC色顶点的连线
深浅变化:RGB顶点和CMY顶点到原点和白色顶点的中轴线的距离
明暗变化:中轴线的点的位置,到原点,就偏暗,到白色顶点就偏亮
HSV图像模型
倒锥形模型:
![](https://img-my.csdn.net/uploads/201211/20/1353401545_7912.png)
这个模型就是按色彩、深浅、明暗来描述的。
H是色彩
S是深浅, S = 0时,只有灰度
V是明暗,表示色彩的明亮程度,但与光强无直接联系,(意思是有一点点联系吧)。
![](https://img-my.csdn.net/uploads/201211/20/1353404459_6995.jpg)
3. RGB与HSV的联系
从上面的直观的理解,把RGB三维坐标的中轴线立起来,并扁化,就能形成HSV的锥形模型了。
但V与强度无直接关系,因为它只选取了RGB的一个最大分量。而RGB则能反映光照强度(或灰度)的变化。
v = max(r, g, b)
由RGB到HSV的转换:
HSV对用户来说是一种直观的颜色模型。我们可以从一种纯色彩开始
即指定色彩角H,并让V=S=1,然后我们可以通过向其中加入黑色和白色
来得到我们需要的颜色。增加黑色可以减小V而S不变
同样增加白色可以减小S而V不变。例如,要得到深蓝色,V=0.4 S=1 H=240度。
要得到淡蓝色,V=1 S=0.4 H=240度。" --百度
reshape把指定的矩阵改变形状,但是元素个数不变,
例如,行向量:
a = [1 2 3 4 5 6]
执行下面语句把它变成3行2列:
b = reshape(a,3,2)
执行结果:
b =
1 4
2 5
3 6
若a=[1 2 3
4 5 6
7 8 9]
使用reshpe后想得到b=[1 2 3 4 5 6 7 8 9]
只需要将a转置一下就可以了:
b=reshape(a',1,9)
A = 1:10;
B = reshape(A,[5,2])
B =
1 6
2 7
3 8
4 9
5 10
Reshape Multidimensional Array into Matrix
Reshape a 3-by-2-by-3 array of zeros into a 9-by-2 matrix.
A = zeros(3,2,3);
B = reshape(A,9,2)
B =
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
subplot
Create axes in tiled positions
Syntax
-
subplot(m,n,p)
example -
subplot(m,n,p,'replace')
example -
Description
subplot(m
,n
,p
)
divides the current figure into an m
-by-n
grid and creates an axes for a subplot in the position specified by p
. MATLAB® numbers its subplots by row, such that the first subplot is the first column of the first row, the second subplot is the second column of the first row, and so on. If the axes already exists, then the command subplot(m,n,p)
makes the subplot in position p
the current axes.
![]()
![]()
imagesc
Display image with scaled colors
Syntax
-
imagesc(C)
example -
imagesc(x,y,C)
exist
Check existence of variable, function, folder, or class
Syntax
exist name
exist name kind
A = exist('name','kind
')
| Checks only for built-in functions. |
| Checks only for classes. |
| Checks only for folders. |
| Checks only for files or folders. |
| Checks only for variables. |
if ~exist('plot_progress', 'var') || isempty(plot_progress)
|| means logistic OR!
centroids(:,1)
centroid =
2.4283 3.1579
5.8135 2.6336
7.1193 3.6166
5.8135
7.1194
2.6337
3.6167
initial_centroids =X(randnum(1:5), :);
imread
Read image from graphics file
Syntax
Description
specifies format-specific options using one or more name-value pair arguments, in addition to any of the input arguments in the previous syntaxes.A
= imread(___,Name,Value
)
[
reads the indexed image in A
,map
] = imread(___)filename
into A
and reads its associated colormap into map
. Colormap values in the image file are automatically rescaled into the range [0,1]
.
ind2rgb
Convert indexed image to RGB image
Syntax
RGB = ind2rgb(X,map)
[
reads the indexed image in A
,map
] = imread(___)filename
into A
and reads its associated colormap into map
. Colormap values in the image file are automatically rescaled into the range [0,1]
.
什么是索引图像?
图中圆圈内的就是索引图像的索引表,下面的就是其对应RGB颜色表。
图中小圆圈处的索引号是5,对应RGB颜色的第5行,所以该处RGB颜色实际是0.2902 0.0627 0.0627
索引图像的作用就是体积小,方便传输,只需要把索引表传输过去,接收方用对应的RGB颜色表还原就行。
RGB图像模型。
三维坐标:
原点到白色顶点的中轴线是灰度线,r、g、b三分量相等,强度可以由三分量的向量表示。
用RGB来理解色彩、深浅、明暗变化:
色彩变化: 三个坐标轴RGB最大分量顶点与黄紫青YMC色顶点的连线
深浅变化:RGB顶点和CMY顶点到原点和白色顶点的中轴线的距离
明暗变化:中轴线的点的位置,到原点,就偏暗,到白色顶点就偏亮
HSV图像模型
倒锥形模型:
这个模型就是按色彩、深浅、明暗来描述的。
H是色彩
S是深浅, S = 0时,只有灰度
V是明暗,表示色彩的明亮程度,但与光强无直接联系,(意思是有一点点联系吧)。
3. RGB与HSV的联系
从上面的直观的理解,把RGB三维坐标的中轴线立起来,并扁化,就能形成HSV的锥形模型了。
但V与强度无直接关系,因为它只选取了RGB的一个最大分量。而RGB则能反映光照强度(或灰度)的变化。
v = max(r, g, b)
由RGB到HSV的转换:
HSV对用户来说是一种直观的颜色模型。我们可以从一种纯色彩开始
即指定色彩角H,并让V=S=1,然后我们可以通过向其中加入黑色和白色
来得到我们需要的颜色。增加黑色可以减小V而S不变
同样增加白色可以减小S而V不变。例如,要得到深蓝色,V=0.4 S=1 H=240度。
要得到淡蓝色,V=1 S=0.4 H=240度。" --百度
reshape把指定的矩阵改变形状,但是元素个数不变,
例如,行向量:
a = [1 2 3 4 5 6]
执行下面语句把它变成3行2列:
b = reshape(a,3,2)
执行结果:
b =
1 4
2 5
3 6
若a=[1 2 3
4 5 6
7 8 9]
使用reshpe后想得到b=[1 2 3 4 5 6 7 8 9]
只需要将a转置一下就可以了:
b=reshape(a',1,9)
A = 1:10; B = reshape(A,[5,2])
B = 1 6 2 7 3 8 4 9 5 10
Reshape Multidimensional Array into Matrix
Reshape a 3-by-2-by-3 array of zeros into a 9-by-2 matrix.
A = zeros(3,2,3); B = reshape(A,9,2)
B = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
subplot
Create axes in tiled positions
Syntax
-
subplot(m,n,p)
-
subplot(m,n,p,'replace')
-
Description
subplot(
divides the current figure into anm
,n
,p
)m
-by-n
grid and creates an axes for a subplot in the position specified byp
. MATLAB® numbers its subplots by row, such that the first subplot is the first column of the first row, the second subplot is the second column of the first row, and so on. If the axes already exists, then the commandsubplot(m,n,p)
makes the subplot in positionp
the current axes.
imagesc
Display image with scaled colors
Syntax
-
imagesc(C)
-
imagesc(x,y,C)