read the values of a 3 x 3 matrix from the user, then output
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
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
Voss
el 28 de Mzo. de 2022
Element = input(sprintf('Enter the value for row %d, column %d: ',row,col));
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!