MATLAB Answers

Simulink: Can 2D selector block return a whole column if there is only 1 column?

5 views (last 30 days)
Robert
Robert on 30 Apr 2015
Answered: Sriram Narayanan on 4 May 2015
Attempting to use the selector block in simulink with the following settings:
  • number of input dimension: 2
  • index option 1: select all
  • index option 2: index vector (port)
My goal here is to be able to pick off columns from a matrix. If for example, I attempt to select column 1 via the index vector port, it works just fine so long as the matrix has more than one column. However, if there is only one column, the selector block returns element (1,1) instead of the entire column.
Is there a way to make this work how I'd like? It should be the equivalent of M(:,idx), but is not. I think it's attempting to be intelligent about the fact that I'm using a selector block on a [nx1] matrix and use the index value for the rows. But really in this case, I'd want to have the whole column returned.
And yes, I realize this would be an empty step, essentially returning the same as the input, however due to the nature of the code, the size of the matrix is undetermined until initialization. So I need the option to pick out a column from a matrix, whether there is only 1 column, or 50.
Thanks!!

Answers (1)

Sriram Narayanan
Sriram Narayanan on 4 May 2015
I am assuming that you are using MATLAB 8.5 (R2015a). On R2015a, I used the selector with your settings on a new model and I was able to retrieve the 1st column irrespective of whether I passed a N x 1 or a N x N matrix.
Please find the model attached.

Community Treasure Hunt

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

Start Hunting!