How to establish a range within a loop statement?

조회 수: 11 (최근 30일)
Jaya Poornima
Jaya Poornima 2022년 3월 28일
댓글: Jaya Poornima 2022년 4월 8일
I have two parameters namely, car pos and truck pos. Usually, I individually assign values for these two parameters to get the output readings. Now, because of an increase in the range of values(let's say i need to assign the values from 1 to 50 for both of the parameters), I need an output where the values are extracted from the given range and an overall output data is produced for each and every single value. I believe that we must incorporate loops here. Can someone help me with this? Also, do I need to implement a separate block for the loop in the simulink model?

채택된 답변

Jakob B. Nielsen
Jakob B. Nielsen 2022년 3월 28일
Sounds like you want to use a for loop, which executes for every specified value you put into the loop. The classic:
for i=1:50
car_pos(i)=something*i + somethingelse*i^2 + constant
end
You will end up with a 1x50 array where entry number i is the function executed with value i.
  댓글 수: 1
Jaya Poornima
Jaya Poornima 2022년 4월 8일
Thank you so much, sir. I have successfully implemented this coding in MATLAB. But I am yet to implement this for loop in Simulink. While coming across a YouTube video, i found that, inorder to implement a for loop in a Simulink model, we must utilize the "for iterator block". Now i will be working on that.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by