matrix playing

2 Ansichten (letzte 30 Tage)
PChoppala
PChoppala am 14 Okt. 2011
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Okt. 2011
blkproc(w1,[2 2],@prod)
  4 Kommentare
PChoppala
PChoppala am 14 Okt. 2011
Worked, but, just a quick question,
What is 'x'?
Walter Roberson
Walter Roberson am 14 Okt. 2011
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 14 Okt. 2011
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 Kommentar
PChoppala
PChoppala am 14 Okt. 2011
Worked!, many thanks mate!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by