How to assign few of the array values with a constant randomly .
4 ビュー (過去 30 日間)
古いコメントを表示
I try with randperm but not getting an idea.
suppose n=10 and m=4;
require array with value '1' in 4 random position from 1 to 10 and othe postions value '0;
Expected result,
i.e array =[1, 0, 0, 1, 0, 0, 0, 0, 1,1] here m=4 and n=10
採用された回答
その他の回答 (2 件)
KALYAN ACHARJYA
2019 年 7 月 23 日
編集済み: KALYAN ACHARJYA
2019 年 7 月 23 日
m=4;n=6;
A=[ones(1,m) zeros(1,n)];
[rows colm]=size(A);
colm_data=randperm(colm);
result=A(:,colm_data)
Please do change according as per your requirements (Minor Change)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!