What is means by f = 1:1:dim ?

3 ビュー (過去 30 日間)
Usman Taya
Usman Taya 2019 年 6 月 4 日
回答済み: Walter Roberson 2019 年 6 月 4 日
I didn't understand the meaning of f = 1:1:dim
Here dim is dimension of problem. kindly someone explain for me?

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 6 月 4 日
1:1:dim is a list of numbers that starts with 1 and increments by 1 each time and whose final value is less than or equal to dim
For example if dim was 4.9 then the list would start with 1. You would then add one to the previous value getting 2. 2 is less than or equal to 4.9 so you put the 2 on the end of the list you are building. Now add 1 to the previous value getting 3 which is in range so put that on the end of the list. So far the list contains 1 then 2 then 3. Now add 1 to the previous number getting 4 and that is less than or equal to 4.9 so you would extend the list to 1 2 3 4. Now add 1 to the previous value, getting 5. 5 is not less than or equal to 4.9 so you stop without putting 5 on the list. That leaves you with 1 2 3 4
In the context of a for loop such as
for f=1:1:5
then the meaning is slightly different. Logically the list 1 2 3 4 5 should be created and used for further processing but in this one case the list is not created in memory. Instead matlab takes a copy of the end points and generates each next value as it needs to.
The meaning of
for f=1:1:dim
is that you will loop assigning one value at a time to f, starting with 1, and adding 1 each time it is time for the next loop, ending when the next value would exceed the recorded end point.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by