multiplying multiple values inside multiple matrices

조회 수: 3 (최근 30일)
Albert
Albert 2013년 9월 24일
Hello,
I have multiple matrices (all quite large, of equal size) that all need to be multiplied into a final matrix. For example, if I have a matrix [2, 2] and another [3, 2], I need to find a way to multiply these two to obtain [6, 4]. The trick being that each matrix value is multiplied by the corresponding value in the same location in all the other matrices.
Thanks
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
편집: Azzi Abdelmalek 2013년 9월 24일
If
A=[1 2;3 4]
B=[1 2;3 4;5 6]
What is the expected result?

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

채택된 답변

Image Analyst
Image Analyst 2013년 9월 24일
Since they are all of the same size, and you want to multiply them element by element, you can simply dot multiply:
c1 = a .* b; % For only two matrices.
c2 = a .* b .* c .* d .* e; % for 5 matrices.
  댓글 수: 1
Image Analyst
Image Analyst 2013년 9월 24일
For your new question on means:
meanOf2 = (a + b) / 2; % Mean of two matrices.
meanOf5 = (a+b+c+d+e)/5; % Mean of 5 matrices.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
Maybe this is what you want
A=[1 2;3 4]
B=[1 2;3 4;5 6]
out=cell2mat(arrayfun(@(x) x*B,A,'un',0))
  댓글 수: 3
Image Analyst
Image Analyst 2013년 9월 24일
Your example did not fit his requirement of "of equal size".
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 24일
I took [2, 2] , [3, 2] for the sizes

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by