Vector to matrix using assignment - Simulink

Simple one I guess : I would like to get from a Vector (1x8) to a Matrix (2x4) using index selection from one or two external constant block(s).
I tried using the assignment block but I guess I don't really understand how to use it here. Expected output is in yellow.

 채택된 답변

Andy Bartlett
Andy Bartlett 2021년 4월 30일

0 개 추천

As Fangjun noted, MATLAB Function block is a good approach.
It can also be done with a combination of reshapes and selector.

추가 답변 (2개)

Andy Bartlett
Andy Bartlett 2021년 4월 28일

0 개 추천

Does the reshape block meet your needs?

댓글 수: 1

David K
David K 2021년 4월 28일
편집: David K 2021년 4월 28일
Hello Andy,
So far I could only get to this result with the reshape block as it only uses dimensions (and not order) of the reference input.
As a first step I would appreciate if you knew a block to create a matrix given a input "divider constant" selecting N first values of input vector for the first row, [N+1 :N+N] values for second row etc... for e.g :

댓글을 달려면 로그인하십시오.

Fangjun Jiang
Fangjun Jiang 2021년 4월 28일

0 개 추천

Your output is a 2x4 matrix. Using Assignment block, you could either
Provide a scalar value in U, assign multiple elements of the 2x4 matrix
Or, Provide the same size (2x4) value in U, assign seletive elements of the 2x4 matrix.
I couldn't figure out a way to do what you want, which is reshape plus shuffle.
The easiest approach is to use a MATLAB Function block. It just needs one line of code.
Y=U(Idx1)

카테고리

제품

릴리스

R2016b

질문:

2021년 4월 28일

답변:

2021년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by