フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by