필터 지우기
필터 지우기

From kron to repmat and reshape

조회 수: 5 (최근 30일)
Luca Gagliardone
Luca Gagliardone 2017년 8월 4일
편집: Luca Gagliardone 2017년 8월 4일
I am trying to perform the same task following two different methods:
Z = 20;
W = 30;
A = 50;
size(a)
ans =
20 30
First method:
b = squeeze(a(:,1));
result1 = kron(b,ones(A,1))*ones(1,A);
size(result1)
ans =
1000 50
Second method:
b = repmat(a,[1,1,A,A]);
c = squeeze(b(:,1,:,:));
result2 = reshape(c,[Z*A,A]);
assert( all(all(result1 == result2)) )
These two methods should give the same answer, the first using kron and the second using repmat and then reshape (or some other function). The problem is that reshape and kron do not move entries in the same way, hence reshape should be substituted with something else (or differently specified). Thanks for the attention.
Sincerely Luca
  댓글 수: 1
Jan
Jan 2017년 8월 4일
b = squeeze(a(:,1)), but b is not used anymore. You calculate result1, but display size(c) - what is "c"? W is not used anywhere. Confusing. I cannot recreate the result with kron reliably. Please edit the question and fix the typos in the code.

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

채택된 답변

Jan
Jan 2017년 8월 4일
Perhaps:
Z = 2;
W = 3;
A = 5;
a = rand(Z, W);
b = squeeze(a(:,1));
c1 = kron(b, ones(A,1)) * ones(1,A); % "b" instead of "a"?!
c2 = reshape(permute(repmat(reshape(a(:,1), [1,1,2]), A, A), [2,3,1]), [], A);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by