how to make Matrix
1 次查看(过去 30 天)
显示 更早的评论
Hi I have a problem Creating a function A, which reads a matrix A and prints the following
information on the screen: where the number of rows and columns in A will appear, the element of
row 2 column 1.
1 个评论
回答(1 个)
Pratik Pawar
2022-5-19
You can use the 'size' function to get the dimensions of the matrix and the 'fprintf' function to display the results.
MATLAB has indexing beginning from 1 instead of 0. The matrix elements can be accessed using two parameters
- Row Number
- Column Number
So, A(2, 1) will return the element at row 2, column 1
Please refer to the following code:
% script_name.m
A = [1 2 3 4; 5 6 7 8; 9 10 11 12];
showInfo(A);
function showInfo(A)
[row, col] = size(A);
fprintf('Number of rows: %d\n', row);
fprintf('Number of columns: %d\n', col);
fprintf('Element at (2, 1): %d\n', A(2, 1));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!