when i used embedded matlab function for performng following code i got the error message.Here input 'Edge' from a sobel filter block,output is y
1 view (last 30 days)
Show older comments
error:1)Colon operands must be all the same type, or mixed with real scalar doubles.
Function 'Embedded MATLAB Function' (#18.178.181), line 10, column 11: "imx" 2)Subscripting into an mxArray is not supported.
Function 'Embedded MATLAB Function' (#18.212.219), line 12, column 13: "Lp(i,j)" 3)Undefined function or variable 'p'. The first assignment to a local variable determines its class.
Function 'Embedded MATLAB Function' (#18.241.242), line 13, column 19: "p"
code:
function y = fcn(Edge)
eml.extrinsic('bwlabel')
[Lp,num] = bwlabel(Edge);
mx=max(max(Lp));
[px,py]=size(Edge);
[imx,imy]=size(Lp);
k=0;
for l=1:1:num
k=k+1;p(k)=0;
for i=1:1:imx
for j=1:1:imy
if Lp(i,j)==l
p(k)=p(k)+1;
end
end
end
end
q=p;
temp=0;
for i=1:1:k
for j=1:1:k-1
if p(j)>p(j+1)
temp=p(j);
p(j)=p(j+1);
p(j+1)=temp;
end
end
end
y=p(k);
0 Comments
Accepted Answer
Kaustubha Govind
on 18 Mar 2013
Since 'bwlabel' is declared as an extrinsic function and is unsupported for code-generation, the block is unable to analyze what the type and size of its outputs Lp and num are. If you pre-define their values with the expected type and size, the error should go away. For example, before calling bwlabel, you may write these lines:
Lp = zeros(size(Edge));
num = 0;
2 Comments
Kaustubha Govind
on 18 Mar 2013
You may want to set breakpoints in your code to see where the "Out of bounds" error occurs. Since you are indexing into a lot of variables, it is hard to tell where you're going wrong.
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!