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

1 Ansicht (letzte 30 Tage)
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 Kommentare
studentambitious
studentambitious am 18 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jos (10584)
Jos (10584) am 14 Okt. 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 am 14 Okt. 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 Kommentare
studentambitious
studentambitious am 18 Okt. 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 am 21 Okt. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices 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