print a matrix in a specific sequence

조회 수: 3 (최근 30일)
Mahmoud Khadijeh
Mahmoud Khadijeh 2019년 6월 11일
편집: madhan ravi 2019년 6월 11일
Hello All ,
I want to print a Matrix like this
A=[5
4
3
2
1
0
5
4
3
2
1
0
.
.];
I want numbers from 1 to 5 to be repeated in this form several times

채택된 답변

Chirag Nighut
Chirag Nighut 2019년 6월 11일
You can use the repmat function here
If you have to print the patter N (here 10) times, use the following code:
A = [5 4 3 2 1 0]';
N = 10;
B =repmat(A, N,1)
  댓글 수: 2
madhan ravi
madhan ravi 2019년 6월 11일
편집: madhan ravi 2019년 6월 11일
Providing a complete solution to a homework problem is not recommended. Provide hints instead thank you.
Mahmoud Khadijeh
Mahmoud Khadijeh 2019년 6월 11일
Thank's "Chirag Nighut ", that's also works for me.
Regards

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

추가 답변 (1개)

Utkarsh Belwal
Utkarsh Belwal 2019년 6월 11일
length = 100 ; % This will produce a 120 length output
A = [] ;
value = 5 ;
for i = 1 : length
A = [A ; value] ;
value = value - 1 ;
if mod(i , 5) == 0
A = [A ; 0] ;
value = 5 ;
end
end
disp(A)
  댓글 수: 1
Mahmoud Khadijeh
Mahmoud Khadijeh 2019년 6월 11일
Thank you very much, yes that's what I want and also repmat works for me

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by