필터 지우기
필터 지우기

how i can fix matlab function block coder.extrinsic issue ?

조회 수: 3 (최근 30일)
zubair younas
zubair younas 2019년 4월 8일
댓글: Walter Roberson 2019년 4월 13일
I am usign MATlab function block in my simulation model as relay such as
function y = fcn(P,T)
if(T <= 12.0)
y=1;
else
if (P <= 4800000)
y=0;
else
y=1;
end
end
and it is working well for my model
but I want to use mean of 5 maximum peaks value in a specific interval such as
function y = fcn(P,T)
if(T <= 12.0)
y=1;
else
if((mean(maxk(findpeaks(P((T >= 12) & (T <= 12.1))),5))) <= 4800000)
y=0;
else
y=1;
end
end
but when I use this command
(mean(maxk(findpeaks(P((T >= 12) & (T <= 12.1))),5)))
in my matlab function then following error appears
Function 'maxk' is not supported for code generation. Consider adding coder.extrinsic('maxk') at the top of the function to bypass code generation
where as this command is forking well in command window, I don’t know why this error appearing and how I can fix it
I need help regarding this issue

답변 (1개)

Walter Roberson
Walter Roberson 2019년 4월 8일
Right after the function line, add the line
coder.extrinsic('maxk');
Note: you will not be able to run your code with any acceleration turned on.
In order to be able to run your code with accelation turned on, you will need to convert to using sort() and extracting the values you are interested in.
  댓글 수: 21
zubair younas
zubair younas 2019년 4월 13일
then what is the solution for this? what changes should i do in my code?
Walter Roberson
Walter Roberson 2019년 4월 13일
You want to examine the peaks of something that is a single reading.
  • You could give up on the idea of "peaks" and simply compare the single value in P to 4800000 .
  • You could use a multi-tap delay line or memory buffer to hold on to a certain number of recent samples, and examine the peaks of those
  • perhaps you could give up on the peaks part, and instead integrate your signal, and subtract from that the integral of the signal taken at an earlier time (and held through a delay line or something similar), and divide by the time difference, to get a mean of the entire signal over that time (there might well be other ways to create a "moving mean" block.) In context, perhaps that moving mean might be good enough for your purposes. It depends: is your signal prone to sharp narrow large spikes and that is why you are looking for peaks, or are you looking for the case where the signal value has become overall large for a while ?
  • perhaps in context it would make sense to transform your timeseries into a constant block where the entire past and future history is available, and have your MATLAB Function Block somehow select from that based on time. Remember, though, that the function block is being invoked repeatedly, always for a specific time, not for a range of times.

댓글을 달려면 로그인하십시오.

카테고리

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