필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
jaah navi
jaah navi 2019년 6월 18일
편집: Andrei Bobrov 2019년 6월 18일
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.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 6월 18일
편집: Andrei Bobrov 2019년 6월 18일
[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개)

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by