필터 지우기
필터 지우기

How to change matrix numbers positions

조회 수: 1 (최근 30일)
Hugo Matias
Hugo Matias 2018년 11월 30일
댓글: Bruno Luong 2018년 11월 30일
I have a matrix generated randomly and I want to change the positions of the numbers
i.e:
X=[2 3 4 5;
7 8 9 1]
to
X=[9 5 1 3;
5 2 8 2]
(I'm the one who chooses the new positions, not random)

답변 (3개)

Georgios Pyrgiotakis
Georgios Pyrgiotakis 2018년 11월 30일
do you mean that you want to randomly reanrage the array?
  댓글 수: 1
Hugo Matias
Hugo Matias 2018년 11월 30일
No, i'm the one who chooses the new positions!

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


Image Analyst
Image Analyst 2018년 11월 30일
Will this work for you?
X = [2 3 4 5;
7 8 9 1]
[rows, columns] = size(X)
X = X(randperm(numel(X))) % Unfortunately reshapes into a row vector.
X = reshape(X, [rows, columns]) % Put back into 2-D
It rearranges elements into a random order.
  댓글 수: 2
Hugo Matias
Hugo Matias 2018년 11월 30일
No, i'm the one who chooses the new positions!
Image Analyst
Image Analyst 2018년 11월 30일
What form do you have your new positions in? A matrix? A vector? Two vectors or two matrices with new rows in one, and new columns in the other? Come on, make it EASY for us to help you, not hard.

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


Bruno Luong
Bruno Luong 2018년 11월 30일
X(randperm(numel(X))) = X
  댓글 수: 4
Hugo Matias
Hugo Matias 2018년 11월 30일
How would I do if I wanted to to change the position of the number at (1,2) to (2,3) , for example?
Bruno Luong
Bruno Luong 2018년 11월 30일
Put 3 in NewPositionYouChoose(6)

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by