필터 지우기
필터 지우기

matrix playing

조회 수: 3 (최근 30일)
PChoppala
PChoppala 2011년 10월 14일
Hi all
i have
w1 =
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0002 1.0000 1.0001 1.0000 1.0001
I want a new matrix with product of all terms in each 2x2 matrix in w1
Eventually, I need a 1x3 matrix.
If I use prod(w1), only the columns get multiplied.
Can anyone help please

채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 14일
blkproc(w1,[2 2],@prod)
  댓글 수: 4
PChoppala
PChoppala 2011년 10월 14일
Worked, but, just a quick question,
What is 'x'?
Walter Roberson
Walter Roberson 2011년 10월 14일
x is the "formal argument" for the anonymous function. It is nearly exactly like the x in
proc result = multiplyblock(x)
result = prod(x(:));
end

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

추가 답변 (1개)

Image Analyst
Image Analyst 2011년 10월 14일
Looks like a job for blockproc().
% Generate sample data.
w1 =[...
1.0000 4.0000 1.0000 2.0000 1.0000 6.0000;
1.0000 1.0002 1.0000 1.0001 1.0000 1.0001]
% Declare a function
fun = @(block_struct) prod(block_struct.data(:))
% Do the job:
result = blockproc(w1,[2 2], fun)
Note I changed w1 to make it easier to see that it actually did the job.
  댓글 수: 1
PChoppala
PChoppala 2011년 10월 14일
Worked!, many thanks mate!

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by