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

38 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(1 个)

Muddasir Muddasir
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