Error while using embedded matlab function block in simulink
12 views (last 30 days)
Show older comments
I want to use this code in the simulink through embedded matlab function block.
function [unew] = cycomplet(u,t)
unew=[];
unew = zeros(1, length(t));
for i = 2:length(t)-1;
if (u(i-1)<u(i))&& (u(i+1)<u(i));
unew(i)=u(i);
else unew(i)=0;
end
end
These code are working fine in matlab, but when i use these code in simulink through embedded matlab function block it is giving following two error.
*error No 1* Coder error:-Matlab function:-Size computation for unew (#23) failed. The size definition did not evaluate to a positive integer value.
error No 2* Error using ==> sf Size computation for unew (#23) failed. The size definition did not evaluate to a positive integer value.
Can anybody please tell me why this error is coming in simulink?? and how to resolve it??
Regards Jeevan Patil
5 Comments
Walter Roberson
on 23 Jan 2012
Perhaps in your code you code disp() the actual size received for u and t ?
Answers (1)
Walter Roberson
on 23 Jan 2012
Simulink arrays cannot be completely variable sized. You must have a maximum length defined for them.
Also, if I recall past postings properly, Simulink does not permit empty arrays. We have no proof in the code you show that t will be non-empty and thus that length(t) will be positive.
2 Comments
Walter Roberson
on 23 Jan 2012
What would your code compute if length(t) is 1 or 2 ? length(t)-1 would then be less than 2 so the for loop would not execute.
Sorry, we were both cleaning up the posting at the same time, so one of your responses got deleted. You were asking what to do and for examples of how to do it.
See Also
Categories
Find more on Sources 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!