How do you initialize an N*M matrix?

조회 수: 2,462 (최근 30일)
Harry
Harry 2013년 6월 26일
편집: Arun 2022년 12월 7일
From the MATLAB help, it says to use:
M = matrix(N, M)
but when I apply this it says that the function 'matrix' is not recognized.
Undefined function 'matrix' for input arguments of type 'double'.
Error in experimental (line 1)
M = matrix(3,3)
  댓글 수: 3
Harry
Harry 2013년 6월 27일
'matrix' not found.
Tulike
Tulike 2017년 7월 12일
M=zeros(N,M)

댓글을 달려면 로그인하십시오.

채택된 답변

Leah
Leah 2013년 6월 26일
편집: MathWorks Support Team 2018년 11월 27일
To initialize an N-by-M matrix, use the “zeros” function. For example, create a 3-by-5 matrix of zeros:
A = zeros(3,5);
You can then later assign specific values to the elements of “A”.
  댓글 수: 3
Abhishek Inamdar
Abhishek Inamdar 2021년 7월 6일
Use "X = ones(n)" and add the values based on the row and column. Use for loop to work on value addition
israt fatema
israt fatema 2021년 8월 25일
Can you please show me how to assign value to A after initialize the N x M matrix? For example i need to create a vector 5 x 5 and with values x = 20 35 49 64 23

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Lokesh Ravindranathan
Lokesh Ravindranathan 2013년 6월 26일
편집: Lokesh Ravindranathan 2013년 6월 26일
I am assuming you are trying to create an empty matrix of zeros of dimensions N*M. You can try the following instead
M = zeros(3,3)
This creates a matrix of zeros of size 3*3.
  댓글 수: 2
per isakson
per isakson 2013년 6월 26일
편집: per isakson 2013년 6월 26일
matrix is a function in the symbolic toolbox.
Lokesh Ravindranathan
Lokesh Ravindranathan 2013년 6월 26일
Oh. Thanks Isakson. I will update my answer. My MATLAB did not have symbolic Math toolbox.

댓글을 달려면 로그인하십시오.


Nitin
Nitin 2013년 6월 26일
you could initialize the matrix,
M = zeros(n,m);

Pau
Pau 2018년 10월 17일
This should make the trick
M = double.empty(N,M,0);
https://uk.mathworks.com/help/matlab/ref/empty.html

Arun
Arun 2022년 12월 7일
편집: Arun 2022년 12월 7일
Here is the documentation for multi dementional arrays in matlab
Here is an example to create and initialize a 3X3 matric
A = [1 2 3; 4 5 6; 7 8 9]
A = 3×3
1 2 3
4 5 6
7 8 9
It is simular to matrix in c programming.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by