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 Kommentare

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 am 28 Apr. 2014
Oh, yes, thanks! I will try it!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB Coder finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 25 Apr. 2014

Kommentiert:

am 28 Apr. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by