I want to create a row matrix of 16 elements and fill in the first 8 elements (as well as the last 8 elements) of it, with integers from 1 to 8.
i.e. result = ( 2 5 2 8 4 1 4 7 3 5 3 7 8 4 6 6 )
Any help could be useful. thanks in advance!

댓글 수: 1

Azzi Abdelmalek
Azzi Abdelmalek 2015년 1월 10일
You can just ask to create a matrix with 16 elements taken randomly from 1 to 8

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

 채택된 답변

Star Strider
Star Strider 2015년 1월 10일

0 개 추천

This seems to do what you want:
result = randi([1 8], 1, 16)
producing:
result =
4 1 3 3 3 2 3 1 8 1 8 4 1 3 6 7

댓글 수: 1

Image Analyst
Image Analyst 2015년 1월 10일
Just a fine point, this gives doubles that have integer values. If you really want an integer data type, cast to an integer data type such as int32:
result = int32(randi([1 8], 1, 16))
whos result % Prove that it's an integer.

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

추가 답변 (1개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2015년 1월 10일

댓글:

2015년 1월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by