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”. Answer from Leah on mathworks.com
🌐
MathWorks
mathworks.com › matlab › get started with matlab
Matrices and Arrays - MATLAB & Simulink
All MATLAB variables are multidimensional arrays, no matter what type of data. A matrix is a two-dimensional array often used for linear algebra. To create an array with four elements in a single row, separate the elements with either a comma (,) or a space.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › matrices and arrays
Creating, Concatenating, and Expanding Matrices - MATLAB & Simulink
Then, create a 4-by-4 matrix whose diagonal elements are the elements of A. ... The createArray function (since R2024a) can return arrays of almost any MATLAB data type. The function uses the same syntax as zeros and ones to define the size of the array, but it also offers several options for specifying the contents of the array.
Discussions

Creating a matrix of specific size, in which I can input each element value.
I would like to create a matrix of a Nx1 size where I can input the value of each the "N" elements of the matrix automatically. For example, if I want a 4x1 matrix, I would like to be able to input the first element, second and so forth manually. Thanks for the help and I hope I made myself clear. ... https://www.mathworks.com/matlabcentral... More on mathworks.com
🌐 mathworks.com
0
0
September 16, 2018
How to create a matrix of size N×N that has ones in the border and zeros inside?
Create a matrix of size N×N that has ones in the border and zeros inside. For example, if N=3 the matrix can be created with ... Make this construction depend on N and work for any positive integer N≥2. Sign in to comment. Sign in to answer this question. ... https://www.mathworks.com/matlabcentral... More on mathworks.com
🌐 mathworks.com
2
0
September 6, 2017
How to create a matrix with arbitrary dimensions
https://www.mathworks.com/matlabcentral/answers/446034-how-to-create-a-matrix-with-arbitrary-dimensions#answer_361913 ... To create an zero array of an arbitray dimensions between 1 and D with arbitry sizes between 1 and S : More on mathworks.com
🌐 mathworks.com
2
0
February 20, 2019
how to generate matrix of size 10X10?
how to generate matrix of size 10X10?. Learn more about matrix MATLAB More on mathworks.com
🌐 mathworks.com
2
0
March 26, 2014
🌐
MathWorks
mathworks.com › matlabcentral › answers › 419258-creating-a-matrix-of-specific-size-in-which-i-can-input-each-element-value
Creating a matrix of specific size, in which I can input each element value. - MATLAB Answers - MATLAB Central
September 16, 2018 - Hello Everyone, I would like to create a matrix of a Nx1 size where I can input the value of each the "N" elements of the matrix automatically. For example, if I want a 4x1 matrix, I would like ...
🌐
MathWorks
mathworks.com › matlab mobile › matlab mobile fundamentals
Creating Matrices and Arrays - MATLAB & Simulink
To create an array with multiple ... in a single column: >> a = [1; 2; 3; 4] a = 1 2 3 4 · To create a matrix that has multiple rows, separate the rows with semicolons....
🌐
Ubcmatlabguide
ubcmatlabguide.github.io › html › matrixOperations.html
Operations on matrices
The spy() function can be used to visualize the sparsity pattern of a matrix. The spalloc() function can be used to preallocate space for a sparse matrix. The following command creates a 100-by-100 matrix with room currently for 10 non-zero elements. More than 10 non-zero elements can be added later but this can be slow as Matlab will need to find a larger chunk of memory and copy the non-zero elements.
Find elsewhere
🌐
MathWorks
mathworks.com › matlabcentral › answers › 446034-how-to-create-a-matrix-with-arbitrary-dimensions
How to create a matrix with arbitrary dimensions - MATLAB Answers - MATLAB Central
February 20, 2019 - https://www.mathworks.com/matlabcentral/answers/446034-how-to-create-a-matrix-with-arbitrary-dimensions#comment_673463 ... You want a Sz-by-Sz-by- ... -by-Sz array, where Dims specfies the number of Sz's
🌐
GeeksforGeeks
geeksforgeeks.org › matlab-matrix
Matlab - Matrix - GeeksforGeeks
February 21, 2022 - In MATLAB, the matrix is created by assigning the array elements that are delimited by spaces or commas and using semicolons to mark the end of each row. Now let's have a glance at some examples to understand it better.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 123126-how-to-generate-matrix-of-size-10x10
how to generate matrix of size 10X10? - MATLAB Answers - MATLAB Central
March 26, 2014 - I have generated the numbers from 1 to 10 by using the command 1:1:10. I got 1X10 size matrix but I want the matrix of size 10X10 i.e, each column values should be same. Please help me. ... https://www.mathworks.com/matlabcentral/answers/123126-how-to-generate-matrix-of-size-10x10#comment_204265
🌐
Reddit
reddit.com › r/matlab › how do i make a fixed size array/matrix from a given dimension through variables?
r/matlab on Reddit: How do I make a fixed size array/matrix from a given dimension through variables?
June 13, 2021 -

I need to be able to create a matrix or pre-allocate a matrix from given ROW and COLUMN inputs. I've found that if I do something like:

a = zeros(10,12)

SIMULINK grants it as a fixed size matrix.

But if I do stuff like following:

function y = matrix(row,col)

a = zeros(row,col)

y = a

SIMULINK thinks the dimensions are variable. Thus it's a variable sized matrix. So I can't wire the output to another block which wants fixed size matrix.

What is the solution here, if I want to take my matrix dimensions from variables?

🌐
YouTube
m.youtube.com › watch
How to Creating Matrices in MATLAB | MATLAB Tutorial 3
Share your videos with friends, family, and the world
Published: August 21, 2018
🌐
MathWorks
mathworks.com › matlabcentral › answers › 113341-matlab-function-for-defining-the-size-of-a-matrix
Matlab function for defining the size of a matrix - MATLAB Answers - MATLAB Central
January 22, 2014 - The size of matrix A (in the model) is 14x14 B= 14x2 C= 14x14 D= 14x2 Now I need to know, how to use the function below to make the size of matrix B as 14x2 B=zeros(size(A,1),1) Please d...
🌐
MathWorks
mathworks.com › matlabcentral › answers › 121976-how-can-i-create-an-array-of-fixed-length
How can I create an array of fixed length? - MATLAB Answers - MATLAB Central
March 17, 2014 - https://www.mathworks.com/matlabcentral/answers/121976-how-can-i-create-an-array-of-fixed-length#comment_483021 ... @Akshay Joshi: You will have to either check the indices before allocating, or check the vector size after allocating.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 423738-how-to-predefine-a-matrix-with-one-unknown-dimension
how to predefine a matrix with one unknown dimension - MATLAB Answers - MATLAB Central
October 12, 2018 - Just define a matrix that's well large enough to hold all your numbers, like a few million elements or whatever. ... Then do whatever you need to do assigning rows and columns in v, then, if you've kept track of the max column number, you can ...
🌐
MathWorks
mathworks.com › matlab › language fundamentals › matrices and arrays
ones - Create array of all ones - MATLAB
X = ones(n) returns an n-by-n matrix of ones. ... X = ones(sz1,...,szN) returns an sz1-by-...-by-szN array of ones where sz1,...,szN indicates the size of each dimension.
🌐
MathWorks
mathworks.com › matlab › language fundamentals › matrices and arrays
Empty Arrays - MATLAB & Simulink
In most cases where you need to create an empty array, a 0-by-0 array is sufficient. However, you can create empty arrays of different sizes by using functions like zeros or ones. For example, create a 0-by-5 matrix and a 3-by-0-by-5 array.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 1566848-create-a-matrix-of-matrices
Create a matrix of matrices - MATLAB Answers - MATLAB Central
October 19, 2021 - Currently this is done by stacking the constituent matrices into a master matrix, but calling the values requires the index be increased/decreased by a multiple of one of it's lengths (depending on how it's constructed).