Every 2 rows (2x2 matrix) to perform determinant calculation

Hi all, can i know how to extract every two rows of my data to perform determinant calculation?
For example i have data:
1 2
3 4
5 6
7 8
9 10
11 12
so i want to select every two rows in order to perform determinant calculation, how can i do that? my final results should be:
-2
-2
-2
Regards,

 Accepted Answer

m=size(data,1);
i=1:2:m;
j=2:2:m;
determinants = data(i,1).*data(j,2)-data(j,1).*data(i,2),

3 Comments

Thx matt,
i would like to inquire another possible solutions for my problem.
for example if i have a set of data (10x1 matrix):
1
2
3
4
5
6
7
8
9
10
i want to extract every two rows to do multiplication with a 5x1 matrix:
1
2
3
4
5
how can i do that ? my final results should be:
1
2
6
8
15
18
28
32
45
50
i made attempt to acquire a solution using the code you suggested but i don't think i did it correctly.
r=[1;2;3;4;5];
m=size(data,1);
i=1:2:m; j=2:2:m;
n=[data(i) data(j)];
results=r.*n;
many thanks :)
results = bsxfun(@times,r,n);
or
results = kron(r,[1;1]).*data
it works perfectly. thank you so much mate :]

Sign in to comment.

More Answers (2)

A=[1 2 ;3 4 ;5 6 ;7 8 ;9 10 ;11 12 ]
B=reshape(A',2,2,[])
out=arrayfun(@(x) det(B(:,:,x)),1:size(B,3))
thank you so much of both of your responses, appreciate :)

Asked:

on 24 Nov 2013

Commented:

on 25 Nov 2013

Community Treasure Hunt

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

Start Hunting!