can we find the original matrix back from the modified matrix whose rows were initially swapped .

4 visualizzazioni (ultimi 30 giorni)
hi.... please solve my problem I have a matrix A of size say mxn. The rows of matrix A are swapped(interchanged) and found a matrix B. Swapping of the rows is done according to the values already given in form of two vectors. Can we reconstruct the original matrix A from matrix B. For reconstructing no vectors are given.
  3 Commenti
studentambitious
studentambitious il 18 Ott 2016
i m writing an example A=[2 3 4 5 6 ;9 8 7 5 6; 5 6 9 3 6;5 4 7 6 9]; A1=A; Lx=[ 2 1 ]; Bx=[4 3 ]; What i want is to swap the rows of matrix A according to index given in Lx and Bx..eg swap row 2(Lx(1)) with row4(Bx(1)) , row 1 with row 3 likewise... the resultant matrix is matrix B... now how can we recover matrix A from matrix B.

Accedi per commentare.

Risposte (2)

Jos (10584)
Jos (10584) il 14 Ott 2016
So you know B and the vector v that contains the two rows where swapped to create A. Then it is easy:
A = magic(5)
v = [2 3] % swap row 2 and 3
% construct B, (this could be done simpler, see reconstruction method)
B = A ;
B(v(1),:) = A(v(2),:) ;
B(v(2),:) = A(v(1),:) ;
% reconstruct A
A2 = B ;
A2(v,:) = B(v([2 1]),:) ;
isequal(A,A2) % success!

Steven Lord
Steven Lord il 14 Ott 2016
I have a standard deck of 52 playing cards in some arbitrary initial order. [I have written down the initial ordering of the cards ahead of time.] I permute (shuffle) the deck according to a permutation vector (making sure not to let you see me do it, so you can't glean any information from the movements of my hands.) I give you the permuted deck of cards and ask you to return them to the original ordering I wrote down.
If I tell you that original ordering, the problem is easy.
If I tell you the permutation vector I used to shuffle the deck, the problem is easy.
If I tell you neither of those things, the problem is very difficult. There are about 8e67 ( factorial(52) ) different possible orderings of a standard deck of 52 cards. Good luck choosing the correct one at random.
So without some additional information, unshuffling the deck (inverting the permutation I applied) or unshuffling the rows in the matrix is going to be tough to do.
  2 Commenti
studentambitious
studentambitious il 18 Ott 2016
yes we can add information(like adding a column(permutation vector) in the front of a matrix but i dont know how to write matlab code for it..please help
studentambitious
studentambitious il 21 Ott 2016
Mr. stevan can u please help in writing the matlab code for the program in which rows of a matrix are swapped.i think if we add a column in the front of a matrix that mention the order of rows , we can keep track of the origional location of the rows....kindly help in writing the matlab code for it

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by