mismatch data types in Matlab Coder

Hi all,
I am struggling with data tyoes/dimensions of variables when using MATLAB Coder.. In the entry file(the main .m file), we can specify the data types of the arguments in the penal. But for the other functions/.m files called in the main function, it is really annoying. For example,
Matlab code: next_e = find(((v2==BEE(:,1))&(v1~=BEE(:,2)))|((v2==BEE(:,2))&(v1~=BEE(:,1)))); if BEE(next_e,1) == v2
Since next_e can only be a number not vector, so in matlab it is fine as BEE(next_e,1) is a number and v2 is also a number.. But when calling codegen, it said:
Expected a scalar. Non-scalars are not supported in IF or WHILE statements, or with logical operators. Instead, use ALL to convert matrix logicals to their scalar equivalents.
and the next_e has size ?*1 but v2 is 1*1 so there is problem...
Could anyone have any idea about such problem? Many thanks!

2 个评论

How do you know that next_e is just a number and not a vector (or even empty)? The find function will return the indices of all elements in BEE that match the criteria. Perhaps indicating that you just want the first element that satisfies this condition will be sufficient:
next_e = find(((v2==BEE(:,1))&(v1~=BEE(:,2)))|((v2==BEE(:,2))&(v1~=BEE(:,1))),1);
A ,1 has been added as the second input to the find function. Run (from console) help find for details.
Oh, yes, thanks! I will try it!

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB Coder 的更多信息

产品

提问:

2014-4-25

评论:

2014-4-28

Community Treasure Hunt

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

Start Hunting!

Translated by