필터 지우기
필터 지우기

Creating matrix with different elements

조회 수: 1 (최근 30일)
M.R. Ebrahimi
M.R. Ebrahimi 2020년 11월 12일
댓글: Ameer Hamza 2020년 11월 12일
Hi
I have to create a 3 * 4 matrix whose elements are between 3 and 8, but the element of each row will be different. How can I creat it?

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 12일
편집: Ameer Hamza 2020년 11월 12일
This is one way
lb = 3;
ub = 8;
M = rand(3,4);
for i = 1:size(M,1)
M(i,:) = randperm(ub-lb+1, size(M,2))+lb-1;
end
Result
>> M
M =
4 5 8 6
3 6 7 8
7 3 6 8
  댓글 수: 2
M.R. Ebrahimi
M.R. Ebrahimi 2020년 11월 12일
Thank you
Ameer Hamza
Ameer Hamza 2020년 11월 12일
I am glad to be of help!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by