read the values of a 3 x 3 matrix from the user, then output
20 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Voss
on 28 Mar 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 Comments
Voss
on 28 Mar 2022
Element = input(sprintf('Enter the value for row %d, column %d: ',row,col));
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!