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

9 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating 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