필터 지우기
필터 지우기

How to programming the matrix of mn ?

조회 수: 3 (최근 30일)
Mark
Mark 2021년 5월 18일
댓글: Mark 2021년 5월 19일
I would like to know how to coding the matrix with the following pattern?
Could I use the "for" or ''while" loop or is there any other way to deal with it?
mn=[1 1; 1 3; 1 5; 1 7; 3 1; 3 3; 3 5; 3 7; 5 1; 5 3; 5 5; 5 7; 7 1; 7 3; 7 5; 7 7...........]
Thank you very much!

채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 18일
n = 2*randi([2, 5])+1
n = 5
[T1, T2] = meshgrid(1:2:n);
nm = [T1(:), T2(:)]
nm = 9×2
1 1 1 3 1 5 3 1 3 3 3 5 5 1 5 3 5 5
  댓글 수: 1
Mark
Mark 2021년 5월 19일
Really appreciate your help, Walter Roberson !

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

추가 답변 (1개)

Jonas
Jonas 2021년 5월 18일
you could e.g. use the kronecker product like
[kron((1:2:18)',ones(4,1)) kron(ones(numel(1:2:18),1),(1:2:7)')]
  댓글 수: 1
Mark
Mark 2021년 5월 18일
편집: Mark 2021년 5월 18일
Thanks for your response!
Sorry I made you misunderstand.
I mean the pattern should like this
for example
for 1 to 3
then
mn=[1 1;1 3;3 1;3 3]
for 1 to 5
mn=[1 1;1 3;1 5;3 1;3 3;3 5;5 1;5 3;5 5]
for 1 to 7
mn=[1 1; 1 3; 1 5; 1 7; 3 1; 3 3; 3 5; 3 7; 5 1; 5 3; 5 5; 5 7; 7 1; 7 3; 7 5; 7 7]
for 1 to 9
mn=[1 1; 1 3; 1 5; 1 7; 1 9;3 1; 3 3; 3 5; 3 7;3 9; 5 1; 5 3; 5 5; 5 7; 5 9; 7 1; 7 3; 7 5; 7 7;7 9;9 1;9 3;9 5;9 7;9 9]
and so on
Thanks a lot!

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by