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.
ryan
ryan 2014년 4월 28일
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