필터 지우기
필터 지우기

how to create a matrix (3*3) from 1 to 9 by using for loop

조회 수: 22 (최근 30일)
prog computer
prog computer 2019년 12월 22일
답변: Muddasir Muddasir 2022년 3월 17일
How to create a matrix (3*3) from 1 to 9 by using For loop like:
1 2 3
4 5 6
7 8 9
.................
for i=1:3 %row%
for j=1:3 %column%
a(i,j)= input('a=');
end
end
disp (a)
..................
I wrote this code, but I don't want to input the digits from 1 to 9 by keyboard. I want the computer enter these digits automatically by using For loop

채택된 답변

BN
BN 2019년 12월 22일
I think you don't need any for loop to achieve this goal. try this code below:
reshape( 1:9, 3, 3) .'
  댓글 수: 8
prog computer
prog computer 2019년 12월 22일
thank u very much
prog computer
prog computer 2019년 12월 22일
clc,clear
k=1;
for i=1:3
for j = 1:3
a(i,j)=k;
k=k+1;
end
end
disp (a)

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

추가 답변 (1개)

Muddasir Muddasir
Muddasir Muddasir 2022년 3월 17일
for i=1:3 for j=1:3 a(i, j) =input('a=') : end end disp(a)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by