matlab 시뮬링크 만들고 싶어요
-
게시물 수정 , 삭제는 로그인 필요
% 시뮬레이션을 위한 초기값 설정
minMoisture = 10; % 최소 수분 레벨
maxMoisture = 50; % 최대 수분 레벨
currentMoisture = 8; % 초기 수분 레벨을 8로 설정
% 그래프를 그릴 Figure 생성
figure;
h = animatedline;
addpoints(h, 0, currentMoisture); % 초기값을 그래프에 추가
% 시뮬레이션 시작
for t = 1:100
% 시간에 따라 수분 감소
currentMoisture = max(minMoisture, currentMoisture - 1); % 1씩 감소하도록 설정
% 토양 수분 출력
fprintf('현재 토양 수분: %d\n', currentMoisture);
% 그래프 업데이트
addpoints(h, t, currentMoisture);
xlim([t - 20, t + 20]); % 그래프의 x-축 범위 설정
% 그래프 그리기
drawnow;
% 수분 부족 시 물 주기 (시뮬레이션)
if currentMoisture <= 15
fprintf('물을 주어야 합니다. 현재 수분: %d\n', currentMoisture);
% 물을 주는 동작을 여기에 구현합니다.
currentMoisture = randi([minMoisture, maxMoisture]); % 다시 무작위 수분 레벨 설정
fprintf('물을 주었습니다. 현재 수분: %d\n', currentMoisture);
else
fprintf('물 주지 않아도 됩니다. 현재 수분: %d\n', currentMoisture);
end
pause(1); % 1초 대기 (시뮬레이션 시간)
end
이 코드를 시뮬 링크로 만들고 싶은데 어떤 블록을 어디에 연결해야 하는지 알려 주실 수 있으실까요
#matlab 시뮬링크 #시뮬링크 matlab function