Borrar filtros
Borrar filtros

the dimensions of matrix and the size is different?

8 visualizaciones (últimos 30 días)
Bisma Waheed
Bisma Waheed el 21 de Mzo. de 2018
Comentada: Jan el 21 de Mzo. de 2018
I reshaped the dimensions of my matrix in my code. When i run this:
x=[M,N] y=[M2,P]
i get the following answer x =
335 80
y =
335 2
However, when i check the size with this command sz1= size(x) sz2=size(y)
i get the following answer: sz1 =
1 2
sz2 =
1 2
my code is this
function d = disteu(x, y) % DISTEU Pairwise Euclidean distances between columns of two matrices % % Input: % x, y: Two matrices whose each column is an a vector data. % % Output: % d: Element d(i,j) will be the Euclidean distance between two % column vectors X(:,i) and Y(:,j) % % Note: % The Euclidean distance D between two vectors X and Y is: % D = sum((x-y).^2).^0.5
% D = sum((x-y).^2).^0.5
[M, N] = size(x);
[M2, P] = size(y);
if (M ~= M2)
C=padarray(x,[21,0],0,'post');
sz=size(C);
[M,N]= size(C);
end x=[M,N] y=[M2,P]
sz1= size(x) sz2= size(y)
d = zeros(N, P);
if (N < P) copies = zeros(1,P); for n = 1:N d(n,:) = sum((x(:, n+copies) - y) .^2, 1); end else copies = zeros(1,N); for p = 1:P d(:,p) = sum((x - y(:, p+copies)) .^2, 1)'; end end
d = d.^0.5;
  2 comentarios
M
M el 21 de Mzo. de 2018
If
x =
335 80
then it is a vector of dimension 1x2 : one row, two columns. So the size that you get does correspond. What is the problem ?
Jan
Jan el 21 de Mzo. de 2018
SQRT is faster than the power operation .^0.5

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 21 de Mzo. de 2018
This is exactly the expected behavior.
x = [M,N]
y = [M2,P]
This concatenates the scalars M and N, as well as M2 and P horizontally. Then both variables have the dimensions [1, 2], as the size() command tells you. The contents of x and y can be [335, 80] and [335, 2], but this is no contradiction.
  6 comentarios
Jan
Jan el 21 de Mzo. de 2018
@Bisma:
B = rand(314, 1); % For testing only, use your data
B(355, 16) = 0
fills all needed elements with zeros automatically.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by