필터 지우기
필터 지우기

Creating a 15x15 matrix with certain specifications

조회 수: 16 (최근 30일)
nick
nick 2016년 3월 11일
댓글: Star Strider 2016년 3월 11일
Hello everyone,
I am having trouble constructing a 15x15 matrix with the following specifications:
- it should only contain three numbers (0, 1, 2)
- there should be 110 0s (48.89% are zeros)
- there should be 110 1s (48.89% are ones)
- there should be 5 2s (2.22% are twos)
Any hints and explanations are greatly appreciated

채택된 답변

Star Strider
Star Strider 2016년 3월 11일
You didn’t say if you wanted it to be random or non-random.
I would create the initial vector as:
v = [zeros(1, 110) ones(1, 110) 2*ones(1,5)];
then for a non-random matrix, just use the reshape function, and for a random matrix, use the randperm function first, then reshape.
  댓글 수: 2
nick
nick 2016년 3월 11일
Thanks! I was looking for a random matrix, so randperm and reshape worked great!
Star Strider
Star Strider 2016년 3월 11일
My pleasure!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by