find function size mismatch in simulink

2 visualizaciones (últimos 30 días)
Henri French
Henri French el 8 de Mzo. de 2017
Respondida: Kushagr Gupta el 17 de Mzo. de 2017
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!

Respuestas (1)

Kushagr Gupta
Kushagr Gupta el 17 de Mzo. de 2017
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.

Categorías

Más información sobre Simulink en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by