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 件のコメント
Geoff Hayes
2014 年 4 月 25 日
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
2014 年 4 月 28 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB Coder についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!