Code covered by the BSD License  

Highlights from
Permute a Matrix

5.0

5.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.55 KB File ID: #25148

Permute a Matrix

by Andrey Popov

 

27 Aug 2009 (Updated 29 Oct 2009)

From given order of rearrangement constructs the permutation matrix P and computes B = P'*A*P

| Watch this File

File Information
Description

PERMM Permutates a matrix A by given indexes by computing B = P'*A*P

B = permm(A,indx)
[B,P] = permm(A,indx)

The function applies simultaneous column and row permutation, that is by
given indexes indx = [k j m ...] the function rearranges the elements of A
so that B11=Akk, B12=Akj, ... B21 = Ajk, B22=Ajj, ...

Example
A = [11 12 13 % initial matrix
       21 22 23
       31 32 33]
idp = [2 3 1] % order of rearrangement
B = permm(A, idp); % rearranged matrix
% B = [22 23 21
% 32 33 31
% 12 13 11]

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
27 Aug 2009 Jos (10584)

This function does not work (and rightfully so!) when 1) the input is not square or when idp does not contain a permutation of all N numbers between 1 and N (for instance [1 3 3]). However, such likely inputs lead to unfriendly error messages, so I suggest you add some error checks in your code.
Furthermore, P can be defined more easily as
  P = eye(size(A)) ;
  P = P(idp,:) ;
Finally, the help section is quite nice, but lacks a description of the third output. And, btw, is the copyright really needed given the BSD license. So, room for improvement.

28 Aug 2009 Jos (10584)

I was a little sloppy .. I meant the second output ...

27 Jan 2010 Elmar  
Please login to add a comment or rating.
Updates
29 Oct 2009

Implements some checks of the input variables and an easier construction of the permutation matrix.

Tag Activity for this File
Tag Applied By Date/Time
permutate Andrey Popov 27 Aug 2009 10:02:51
matrix Andrey Popov 27 Aug 2009 10:02:51

Contact us at files@mathworks.com