Trouble with variable-input sizes in Embedded Matlab
2 views (last 30 days)
Show older comments
So I wrote this code that basically takes a look at the areas of different objects in two different images and then Identifies which objects correspond to the other ones based on how close they are in area. I need it for a simulink model and it runs fine in matlab. Just can you please help me, So here is the base code:
function Pairs = fcn(areas1,areas2,c)%Areas1 and Areas 2 are the areas from the retrospective clouds c is the the number of objects this is obtained from the blob analysis block in simulink%
%#codegen
count = c(:,1);
Pairs = zeros(2,count);
l = 1;
for f = 1:count
end
for e = 1:count
Constant = 50000;
for f = 1:count
d = abs(areas1(:,e) - areas2(:,f));
if d < Constant
Constant = d;
test = [e,f];
end
end
Pairs(:,l) = test;
l = l + 1;
end
And I get the following errors please help me resolve them:
Data 'Pairs' (#230) is inferred as a variable size matrix, while its specified type is something else.
MATLAB Function Interface Error: Error in port widths or dimensions. Invalid dimension has been specified for input ' SFunction '.
Then the usual parsing errors and then I also get these errors:
Class mismatch (double ~= int32). The class to the left is the class of the left-hand side of the assignment.
Function 'MATLAB Function' (#135.249.257), line 13, column 13: "Constant" Launch diagnostic report.
Any help will be extremely appreciated
0 Comments
Answers (3)
Fangjun Jiang
on 4 Aug 2011
The number of ports and the port width of a Simulink block need to be fixed before the simulation starts. "Pairs" is the output of the function thus is treated as the outport of the Embedded MATLAB Function. However, the size of Pairs inside the code is defined as Pairs=zeros(2,count) and "count" is further determined by the input variable c. Anyway, the message is saying that you can not have this type of variable size port width.
0 Comments
Denis Gurchenkov
on 4 Aug 2011
To fix this problem, go to Ports and Data Manager (menu Tools / Edit Data Ports), click on the line for "Pairs", check the checkbox "Variable Size", and enter the maximum size of the Pair variable in the size field.
My guess is that the size of "Pairs" should be something like
[ size(c,1) 10 ]
of course, "10" is just my guess, type in some value that is large enough to cover the number of columns in "Pairs".
0 Comments
Jon
on 19 Nov 2011
I'm having the same issue. What causes it to infer that it is variable size? I can get it to pass the variable size variable but the integrator block won't accept a variable size input. How can I get it to stop inferring that it is variable sized?
1 Comment
Kaustubha Govind
on 21 Nov 2011
Jon: How you write your code determines whether an output is variable-size or not. If you know that your output has a fixed-size, then pre-allocate it at the beginning of the function, and avoid growing it dynamically.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!