read the values of a 3 x 3 matrix from the user, then output

14 ビュー (過去 30 日間)
Shuoze Xu
Shuoze Xu 2022 年 3 月 28 日
コメント済み: Voss 2022 年 3 月 28 日
Read the values of a 3 x 3 matrix from the user, then output the outlier rows and columns
% output demo
Sample Output:
Enter the values for row 1, column 1: 5
Enter the values for row 1, column 2: 4
Enter the values for row 1, column 3: 6
Enter the values for row 2, column 1: 1
Enter the values for row 2, column 2: 2
Enter the values for row 2, column 3: 3
Enter the values for row 3, column 1: 6
Enter the values for row 3, column 2: 8
Enter the values for row 3, column 3: 9
5 4 6
1 Nan 3
6 8 9
This is my code
% create a 3*3 matrix
numRow = 3;
numCol = 3;
vector = []; % create an empty to store the elements
for row = 1:numRow
for col = 1:numCol
Element = input('Enther the value for row, column: ');
vector = [vector Element];
end
end
In my code, it is not a 3*3 matrix.

採用された回答

Voss
Voss 2022 年 3 月 28 日
% create a 3*3 matrix
numRow = 3;
numCol = 3;
matrix = []; % create an empty to store the elements
for row = 1:numRow
vector = [];
for col = 1:numCol
Element = input('Enther the value for row, column: ');
vector = [vector Element];
end
matrix = [matrix; vector];
end
  3 件のコメント
Shuoze Xu
Shuoze Xu 2022 年 3 月 28 日
May you tell me how do I implement output like this?
Enter the values for row 1, column 1: 5
Enter the values for row 1, column 2: 4
Enter the values for row 1, column 3: 6
Enter the values for row 2, column 1: 1
Enter the values for row 2, column 2: 2
Enter the values for row 2, column 3: 3
Enter the values for row 3, column 1: 6
Enter the values for row 3, column 2: 8
Enter the values for row 3, column 3: 9
i want the number of row and column showed on the input
Voss
Voss 2022 年 3 月 28 日
Element = input(sprintf('Enter the value for row %d, column %d: ',row,col));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by