필터 지우기
필터 지우기

Error while using embedded matlab function block in simulink

조회 수: 16 (최근 30일)
Jeevan Patil
Jeevan Patil 2012년 1월 23일
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