MATLAB Answers

0

Could anyone help me how to shuffle the numbers in each column

Asked by jaah navi on 18 Jun 2019
Latest activity Edited by Andrei Bobrov
on 18 Jun 2019
A=[3.8723 3.6040 3.3271 3.0534 2.8094 2.6242;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0;
0 0 0 0 0 0]
I want to shuffle the numbers present in each column to oher places of that corresponding column in a way such that sum(A,2) should not be zero
For example i want to shuffle the number in the following manner.
[3.8723 0 0 3.0534 0 0;
0 0 3.3271 0 0 0;
0 3.6040 0 0 0 0;
0 0 0 0 0 2.6242;
0 0 0 0 2.8094 0]
could anyone please help me on it.

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Andrei Bobrov
on 18 Jun 2019
Edited by Andrei Bobrov
on 18 Jun 2019
 Accepted Answer

[m,n] = size(A);
out = zeros(m,n);
out([randperm(m) + (0:m-1)*m,randi(m,1,n-m)+m^2]) = A(A~=0);

  0 Comments

Sign in to comment.