Error while using embedded matlab function block in simulink

14 次查看(过去 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 个评论
Jeevan Patil
Jeevan Patil 2012-1-23
presently for testing only, i am feeding 2 input through constant block. In constant block i am entering the input vector of dimension 1x101
Walter Roberson
Walter Roberson 2012-1-23
Perhaps in your code you code disp() the actual size received for u and t ?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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
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.
Jeevan Patil
Jeevan Patil 2012-1-23
if length(t) is 1 , my code is not calculating anything. Basically i want to find peak in the signal.
My output will be signal which is having values of peak only, rest of the values should be zero.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by