필터 지우기
필터 지우기

Embedded Matlab Function - Output for every calculation

조회 수: 2 (최근 30일)
Sheetansh Kaushik
Sheetansh Kaushik 2014년 6월 25일
댓글: Sheetansh Kaushik 2014년 6월 26일
Good day to all!
I have some simple code:
function Pr = fcn(unused)
%#eml
k = 100;
Pr = 180;
for i = 1:k
x = Pr * 0.05;
y = Pr - x;
Pr = y;
Pr;
if (Pr == 0 || Pr < 0)
Pr = 180;
end
end
Intention here is simple: Decrease the value of Pr until equal to or less than zero and reset. Concurrently, see the rise and fall of the same on scope. But all i get is a single constant output(as shown in the pic).
WHERE AM I GOING WRONG?
Please let me know!

채택된 답변

Titus Edelhofer
Titus Edelhofer 2014년 6월 25일
Hi,
I think there is a misunderstanding of how this works. The MATLAB code you write is executed at each time step, completely. Since it does not depend on the input, it will give the same result each time (i.e. in each time step) where it is called ...
You could do the following:
  • add a unit delay block to your model
  • feed the output of your EML block to the input of the unit delay and from the unit delay to the EML block
  • remove the loop "for i=1:k" from your MATLAB code
Titus
  댓글 수: 3
Titus Edelhofer
Titus Edelhofer 2014년 6월 25일
Your welcome. Feel free to mark the question as answered then ...
Sheetansh Kaushik
Sheetansh Kaushik 2014년 6월 26일
Sure, done! Although i havent been able to get the step wise decrease of the Pr. If you can, please let me know!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by