Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Save a value to variable (Simulink)

Asked by Agamemnon Krasoulis on 21 May 2012

Hi,

I am using the Submatrix block in Simulink, in which I select the output matrix to contain all the rows of the input matrix and the first x columns (using the "Ending column: index" parameter). I would like though to choose x (the number of columns) according to some other calculations taking place in my algorithm. The Submatrix block, however, does not offer the option to pass its parameters as inputs.

Any idea of how I could achieve that? A possible solution would be if I could save the value of x to a variable and then give the variable name for the Ending column index parameter... Is there any way to do that?

2 Comments

Agamemnon Krasoulis on 21 May 2012

I am afraid that this doesn't help much. I guess if someone wants to learn what the Submatrix block is, he would look it up on MATLAB's help anyway..

K E on 21 May 2012

Sorry, I have removed the comment.

Agamemnon Krasoulis

Products

1 Answer

Answer by Guy Rouleau on 21 May 2012
Accepted answer

Use the Selector block:

http://www.mathworks.com/help/toolbox/simulink/slref/selector.html

You will be able to select rows or columns using a signal.

Based your description, the Index Option "Starting and ending indices (port)" should allow you to select a variable number of columns.

If you are not familiar with variable-size signals, I also recommend going through the "Working with Variable-Size Signals" section of the documentation:

http://www.mathworks.com/help/toolbox/simulink/ug/br4lzsy.html

1 Comment

Agamemnon Krasoulis on 22 May 2012

Thanks. This really helped!

Guy Rouleau

Contact us