필터 지우기
필터 지우기

Why for loop inside MATLAB Function Block doesn't work!

조회 수: 2 (최근 30일)
Babak
Babak 2018년 1월 15일
답변: Walter Roberson 2018년 1월 15일
Hello All,
Why I can not run a simple for loop inside Matlab Function block? My code is as follow:
function [out,power_kw] = fcn(power)
power_kw=power/1000;
for j=1:5
fuel(j)=j+1;
end
FC_min=min(fuel);
out =FC_min;

답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 15일
MATLAB Function Block do not allow arrays to grow. You need to initialize fuel() to its final side before you can write individual elements.
fuel = zeros(1,5);
before the loop.
You could also do
fuel = (1:5)+1;
Seems like a waste of time though since you would know which entry is the minimum ahead of time.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by