matrix playing

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

 采纳的回答

blkproc(w1,[2 2],@prod)

4 个评论

w1 =
Columns 1 through 9
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0001 1.0003 1.0001 1.0008 1.0002 1.0010 1.0002 1.0009 1.0019
Column 10
1.0000
1.0076
>> blkproc(w1, [2,2],@prod)
ans =
Columns 1 through 9
1.0001 1.0003 1.0001 1.0008 1.0002 1.0010 1.0002 1.0009 1.0019
Column 10
1.0076
this is what I get. All elements in each column are multiplied, I need,
if w1 = [a b c d ; e f g h]
w = [axexbxf cxgxdxh]
Can you help with this?
Ah...
blkproc(w1,[2 2],@(x) prod(x(:) )
Worked, but, just a quick question,
What is 'x'?
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.

类别

帮助中心File 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