Azzera filtri
Azzera filtri

the dimensions of matrix and the size is different?

8 visualizzazioni (ultimi 30 giorni)
Bisma Waheed
Bisma Waheed il 21 Mar 2018
Commentato: Jan il 21 Mar 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 Commenti
M
M il 21 Mar 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 ?

Accedi per commentare.

Risposte (1)

Jan
Jan il 21 Mar 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 Commenti
Jan
Jan il 21 Mar 2018
@Bisma:
B = rand(314, 1); % For testing only, use your data
B(355, 16) = 0
fills all needed elements with zeros automatically.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by