When using Embedded MATLAB blocks, if I try to access certain elements of the input parameter, I receive an error message similar to the following:
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
This is unexpected since I know that the input parameter is a vector, even though the error message states that it is a scalar.
Even though you have designed the model such that the input to the EML block is a vector, you will receive this error message if Simulink cannot successfully propagate the signal widths to the EML input (in which case it defaults to a signal width of one). This can sometimes happen for EML blocks that are inside a loop, where the output of the EML block eventually feeds back to the input of the same EML block.
Have a look at the attached example model ("example.mdl") to see a demonstration of this error message. To resolve the error, you need to add more information about the dimension of the signals in your model.
For example, in this case you can do one of the following (this is not an exhaustive list of solutions):
1. Open the EML block editor, and click Tools > Edit Data/Ports. Select the input variable "u", and set the input dimensions to 3. See "solution1.mdl".
2. Place a Signal Specification block in the feedback path, explicitly telling the EML block that this signal has a width of 3. See "solution2.mdl".