필터 지우기
필터 지우기

the dimensions of matrix and the size is different?

조회 수: 8 (최근 30일)
Bisma Waheed
Bisma Waheed 2018년 3월 21일
댓글: Jan 2018년 3월 21일
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
M
M 2018년 3월 21일
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 2018년 3월 21일
SQRT is faster than the power operation .^0.5

댓글을 달려면 로그인하십시오.

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by