필터 지우기
필터 지우기

How to multiply a subset of matrix by a column from another matrix?

조회 수: 1 (최근 30일)
parslee
parslee 2022년 3월 23일
편집: Matt J 2022년 3월 23일
I have an array of 128x9252 and I would like to group them as
A1 = (:,1:257)
A2 = (:,258,514)
A36 = (:,8996:9252)
which will then be multiplied (.*) by y with the corresponding columns - y(:,1), y(:,2), y(:,3), etc.
This is what I want mathematically, A1 * y(:,1), A*y(:,2)), and so on.
How can I go about doing this?
This is what I have so far, but I keep getting an error saying 'Unable to perform assignment because the size of the left side is 128-by-1 and the size of the right side is 128-by-257.' and I'm not sure where the error is.
A = rand(128,9252);
B = zeros(128,257);
for m = 1:257
for n = 1:36
B(:,m) = A(:,257*(n-1)+1:257*n);
end
end

채택된 답변

Matt J
Matt J 2022년 3월 23일
편집: Matt J 2022년 3월 23일
B = pagemtimes( reshape(A,128,257,[]) , reshape(y,257,1,[]) ) ;
B=squeeze(B);
  댓글 수: 4
parslee
parslee 2022년 3월 23일
Sorry, I didn't provide the correct information.
I want to multiply A1 = A(:,1:257), A2 = A(:,258:514), and so on by y = rand(1,257) and after multiplying A1.*y and A2.*y and so on, I want to concatenate them so that it returns to its original matrix size of 128x9252.
So this is what I did,
A = rand(128,9252);
y = rand(1,257);
A_reshape = reshape(A,128,257,[]);
B = A_reshape .* y;
B = reshape(B,128,9252);
Is the last line correct?
Matt J
Matt J 2022년 3월 23일
편집: Matt J 2022년 3월 23일
That would just be,
B=reshape(A,128,257,[]).*y;
B=reshape(B,size(A));
You might, of course, want to consider keeping everything in 128x127x36 form throughout., rather than having to switch back and forth all the time.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by