How to get each pair of of row of a matrix to pass into a function?
Show older comments
Hello Friends,
I have a matrix A of size N x M. I want to get all possible pair of rows, pass them into a function, and get the N x N matrix as output. To be more precise, here is an example of what I want to do:
Example:
Let, A = [1 2; 3 4; 5 6];
Possible row pairs are: {row1, row1}, {row1, row2}, {row1, row3}, {row2, row1}, {row2, row2}, {row2, row3}, {row3, row1}, {row3, row2}, {row3, row3}.
So output will be a 3 x 3 matrix after employing the following steps:
Step-1 For each pair(i,j) or row above
Step-2 function1 = sum(row_i); and function-2 = product(row_j);
Step-3 function3 = sqrt(function1, function2);
Step-4 go to Step-1 and repeat for each pair.
Output Matrix = [f3 f3 f3; f3 f3 f3; f3 f3 f3];
I will appreciate any advice.
Accepted Answer
More Answers (1)
the cyclist
on 23 Oct 2015
I didn't understand Step 3, but this code will do the parts up to there:
A = [1 2; 3 4; 5 6];
[M,N] = size(A);
for m1 = 1:M
row1 = A(m1,:);
s = sum(row1);
for m2 = 1:M
row2 = A(m2,:);
p = prod(row2);
end
end
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!