Error while using embedded matlab function block in simulink
12 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Walter Roberson
2012 年 1 月 23 日
Perhaps in your code you code disp() the actual size received for u and t ?
回答 (1 件)
Walter Roberson
2012 年 1 月 23 日
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 件のコメント
Walter Roberson
2012 年 1 月 23 日
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.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!