필터 지우기
필터 지우기

How to Sort a matrix and a vector?

조회 수: 1 (최근 30일)
Ami
Ami 2011년 6월 5일
I have a vector of 1 column and a matrix of 5 x5, what I need to do is, assing 1 number of P to one numer of time in the first row, like number 1 to 1.7597 and 2 to 2.1777, is like colum per row but I need to assing it randomly, the number 1 have 5 changes to pick a number of the firts row, the number 2 have 5 changes of the row 2. How can I do this? I'm using matlab 2010
P =
1
2
3
4
5
time =
1.7597 1.6340 1.7157 1.6738 2.0185
2.3452 2.1777 2.2866 2.2308 2.6901
3.1412 2.9169 3.0627 2.9880 3.6032
2.8993 2.6922 2.8268 2.7579 3.3256
4.5961 4.2678 4.4812 4.3719 5.2720

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 6월 5일
Try this:
a=eye(5);
b=randperm(5);
c=a(b,:);
time(logical(c))=P;
  댓글 수: 3
Matt Fig
Matt Fig 2011년 6월 6일
If the solution provided by Fangjun is not correct, you should give an example of expected inputs and outputs instead of trying to describe it with words. I see you gave P and time, but what result do you expect. SHOW the result, don't describe it. You can add it to your original question above by clicking the Edit button.
Fangjun Jiang
Fangjun Jiang 2011년 6월 6일
@Ami, You need to clarify your comments. Reading your original question, you want to put P(1) into the first row of time randomly, P(2) into the second row of time randomly, etc. My code did that. Are you asking a separate question?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by