print 2d array using nested foor
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello, I want to print an array as follows
9 9 9 9 9 9 9 9 9 9
8 8 8 8 8 8 8 8 8 8
7 7 7 7 7 7 7 7 7 7
6 6 6 6 6 6 6 6 6 6
5 5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4 4 4 4
3 3 3 3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
댓글 수: 2
Dyuman Joshi
2022년 10월 10일
What have you tried yet? What is the error you are facing? Show your code.
답변 (2개)
Dyuman Joshi
2022년 10월 11일
%Updating your solution
%pre-allocation
a=zeros(10);
for i=1:10
for j=1:10
a(i,j)=10-i;
end
end
a
You can also get the same result (directly) by using some other functions (if using for loop is not necessary) -
[~,y]=meshgrid(9:-1:0)
x=repelem((9:-1:0)',1,10)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!