Main Content

Initialize a Matrix Using a Nontunable Structure Parameter

The following simple example uses a nontunable structure parameter input to initialize a matrix output. The model looks like this:

This model shows a constant block linked to a MATLAB Function block, which outputs to a Display block.

This model defines a structure variable p in its pre-load callback function, as follows:

This image shows the model properties window for the model.

The structure p has two fields, rows and cols, which specify the dimensions of a matrix. The MATLAB Function block uses a constant input u to initialize the matrix output y. Here is the code:

function y = fcn(u, p)
y = zeros(p.rows,p.cols) + u;

Running the model initializes each element of the 2-by-3 matrix y to 99, the value of u:

This image shows the outcome of simulating the model. The Display block outputs a 2-by-3 matrix where each value is 99.

Related Examples

More About