필터 지우기
필터 지우기

1 and 0 matrix

조회 수: 1 (최근 30일)
Offroad Jeep
Offroad Jeep 2015년 5월 5일
편집: Offroad Jeep 2015년 5월 24일
Hi All,..
I want to generate a n by n matrix with 1 and 0 . this matrix should have 10 percent zeros.... in some we cant get exact 10 so + or - 1 or 2 percent will be ok...........

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 5월 5일
n = 5; % size your matrix
k = 10; % your percent
out = zeros(n);
out(randperm(n^2,ceil(n^2*k/100))) = 1;
  댓글 수: 1
Offroad Jeep
Offroad Jeep 2015년 5월 5일
thanks...........

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by