What is the output?
4 ビュー (過去 30 日間)
I am trying to check how the loop works hence, I am displaying the value of n in the for loop but it doesn't seem to work. Why doesn't n get displayed and how is the code (loop) working?
% Doing something here
Walter Roberson 2018 年 4 月 1 日
length of x is 3. When you subtract 1 from a numeric vector you do not change the length so length((x) - 1) is the same length(x) which is 3. So your for loop is
Which will not execute at all.
その他の回答 (1 件)
Roger Stafford 2018 年 4 月 1 日
The vector x has only three elements, [0,.3,.6], so the 'for' instruction reads:
for n = 4:2
Therefore the loop will not execute at all, and this accounts for your lack of results.