print a matrix in a specific sequence
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Chirag Nighut
2019-6-11
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
2019-6-11
编辑:madhan ravi
2019-6-11
Providing a complete solution to a homework problem is not recommended. Provide hints instead thank you.
更多回答(1 个)
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!