2

I have the following functioning code (not my own) that I am attempting to put through C++ code generation.

exampleData = double(dataRight(:,2)) < (pointsRight(1,2) + objLength + 0.101);

The right side of the expression fails, however, citing a size mismatch between the left and right side of the less than sign.

Size mismatch (size [:? x 1] ~= size [0 x 0]).

However, matlab's website says that mismatch sizes are, in this case, the typical use case. Further, no specific exceptions or oddities are noted for Matlab Coder, so I'm a bit lost why I'm getting this error.

6
  • could you share a dump on pointsRight ? have you actually tried this? as far as i know, mismatch size error is when you want to access non-existing row-column.. Commented Aug 28, 2017 at 0:36
  • [0.051759680404457,0.01,0.0784]. The code runs fine outside of coder's attempt to convert it. Additionally, test = (pointsRight(1,2) + objLength + 0.101) runs fine. It is specifically the introduction of < that causes the error. Commented Aug 28, 2017 at 0:52
  • ah i see.. so basically the trouble is (pointsRight(1,2) + objLength + 0.101) scalar (only had a single element), while double(dataRight(:,2)) could have more than a single element (multiple rows).. Commented Aug 28, 2017 at 1:09
  • I'm not sure I understand. Is this a coder-specific restriction? A = [5,4,3]; B= A > 4 works, outside of coder. It yields [1,0,0]. Commented Aug 28, 2017 at 1:43
  • hmm, i get your point. it is indeed weird. i think it is the limitation of C++ code generation. Commented Aug 28, 2017 at 2:51

1 Answer 1

0

Long story short: you must implement a c-style workaround yourself. I believe what caused by issue is the unbounded size of the array, above. I solved this with size(array) and a for loop.

This is the problem code:

dataRight = dataRight(double(dataRight(:,2))>pointsRight(1,2)+0.099 & double(dataRight(:,2))<pointsRight(1,2)+objLength + 0.101,:);

Here is the code that coder accepted:

[widthDataRight,heightDataRight]= size(dataRight)
tempDataRight = zeros(widthDataRight,heightDataRight)
for i = 1:widthDataRight
     val = dataRight(i,2)
     tempDataRight = dataRight(double(val)>pointsRight(1,2)+0.099 & double(val)<pointsRight(1,2)+objLength + 0.101,:);
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.