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 Center および File ExchangeSimulink についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by