how to put only one element randomly in row of matrix

1 回表示 (過去 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
  1 件のコメント
Meriem Ben Kalia
Meriem Ben Kalia 2020 年 8 月 11 日
Thank you very much for the help you have given

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by