randomising a given matrics

hello there i need to randomize a matrix and after that i need to get it back original matrix ... can any one help me

댓글 수: 2

Jan
Jan 2011년 9월 20일
Please explain, what "randomize" and "get back" mean. Do you want to add a random matrix, or sort the rows and/or columns randomly and store the sorting index? A small example might be helpful also.
It is always a good idea to read an own question again and trying to imagine, if a foreign reader has enough information to understand the computational part of the problem. without understanding the problem, a meaningful answer is not possible.
sumit choubey
sumit choubey 2011년 9월 20일
thanx for replying
actually i want to swap the element of a given matrix and and then after than i want to get it back in original matrix
for e.g.
a=[1 3 4;5 6 7]
i want to swap its element to get for e.g [1 4 6;3 7 5]
then i want again the original matrix a=[1 3 4;5 6 7]

댓글을 달려면 로그인하십시오.

 채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 9월 20일

0 개 추천

I'll try to answer :)
% test matrix
a = reshape(1:100,10,10)
% randomize - mixing
idx = reshape(randperm(numel(a)),10,10);
b = a(idx)
[~ c] = sort(idx(:));
% restore matrix a
b = b(reshape(c,10,10))

댓글 수: 8

sumit choubey
sumit choubey 2011년 9월 20일
thanx but its not working
Andrei Bobrov
Andrei Bobrov 2011년 9월 20일
use
[~, c] = sort(idx(:));
or
[non,c] = sort(idx(:));
Grzegorz Knor
Grzegorz Knor 2011년 9월 20일
What is wrong?
Can you paste an error?
Try replace the line:
[~ c] = sort(idx(:));
with:
[ignore, c] = sort(idx(:));
Andrei Bobrov
Andrei Bobrov 2011년 9월 20일
Hi Grzegorz!
% test matrix
a = reshape(1:100,10,10)
% randomize - mixing
b = a;
idx = randperm(numel(a));
b(:) = a(idx)
[~, c] = sort(idx(:));
% restore matrix a
b(:) = b(c)
sumit choubey
sumit choubey 2011년 9월 20일
??? Error: File: randomising1.m Line: 7 Column: 2
An array for multiple LHS assignment cannot contain expressions.
??? Error: File: randomising1.m Line: 7 Column: 2
An array for multiple LHS assignment cannot contain expressions.
sumit choubey
sumit choubey 2011년 9월 20일
this was the error message
sumit choubey
sumit choubey 2011년 9월 20일
thanx it seems to be working .....let me check on my problem ...thanx a lot...
sumit choubey
sumit choubey 2011년 9월 20일
replacing [~c]with[~,c] is working thanx

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by