Error while using embedded matlab function block in simulink

12 views (last 30 days)
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
Jeevan Patil
Jeevan Patil on 23 Jan 2012
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 on 23 Jan 2012
Perhaps in your code you code disp() the actual size received for u and t ?

Sign in to comment.

Answers (1)

Walter Roberson
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
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.
Jeevan Patil
Jeevan Patil on 23 Jan 2012
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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!