필터 지우기
필터 지우기

how to put only one element randomly in row of matrix

조회 수: 3 (최근 30일)
Meriem Ben Kalia
Meriem Ben Kalia 2020년 8월 11일
댓글: Meriem Ben Kalia 2020년 8월 11일
Hello,
Can anyone help me please, I didn't a solution
I'd like to put only one element of row to 1 'randomly' and the other putted in 0
Exemple I have A= zeros (4,3) I like to get A= [0 1 0; 1 0 0; 0 0 1; 1 0 0]

채택된 답변

KSSV
KSSV 2020년 8월 11일
편집: KSSV 2020년 8월 11일
A = zeros(4,3) ;
[m,n] = size(A) ;
for i = 1:m
idx = randperm(n,1) ;
A(i,idx) = 1 ;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by