find function size mismatch in simulink

조회 수: 2 (최근 30일)
Henri French
Henri French 2017년 3월 8일
답변: Kushagr Gupta 2017년 3월 17일
I have a simulink model initialised and run from a Matlab script. Part of the model uses a Matlab function block and to avoid expensive calls to functions not available compiled in simulink I am pre-calculating a number of things and am trying to look up values in the simulink matlab function block.
I have an Mx6 array which is a horizontal concatenation of an Mx3 array of input position vectors:
InVecs = ([x1 y1 z1]; ... [xm ym zm])
and an Mx3 array of output magnetic vectors
OutVecs = ([Bx1 By1 Bz1]; ... [Bxm Bym Bzm])
MAG = [InVecs OutVecs];
Essentially the function which takes the input vector [x1 y1 z1] and returns the output vector [Bx1 By1 Bz1] is very expensive to use in simulink as it requires some extrinsic calls. Hence I am pre-calculating all of them.
When using find in MATLAB something like: index = find(MAG(:,1:3)==vec,1), where vec is a [1x3] vector which is any of the input vectors in InVecs. MATLAB is happy to return the index of this vector. However, in Simulink, a size mismatch error is thrown: (this is for M = 501, but it may be larger or smaller)
Size mismatch (size [501 x 3] ~= size [1 x 3]).
for the line of code:
result = find(MAG(:,1:3)==relES.',1); (relES is a [3x1], hence using the transpose here)
Is there a way of using find like this in Simulink or is there another way to achieve what I'm looking for?
Thanks!

답변 (1개)

Kushagr Gupta
Kushagr Gupta 2017년 3월 17일
I would recommend looking at the ' ismember ' and ' intersect ' functions that can be used as a workaround to find the index of required row in the matrix.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by