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

19 visualizaciones (últimos 30 días)
Shuoze Xu
Shuoze Xu el 28 de Mzo. de 2022
Comentada: Voss el 28 de Mzo. de 2022
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.

Respuesta aceptada

Voss
Voss el 28 de Mzo. de 2022
% 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 comentarios
Shuoze Xu
Shuoze Xu el 28 de Mzo. de 2022
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 el 28 de Mzo. de 2022
Element = input(sprintf('Enter the value for row %d, column %d: ',row,col));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by