What is the size of i after the following code is run in MATLAB? [code]for i=5:1 i=i-2; end[/code]

Answer: b
Explanation: The above loop does not run because the default increment value in MATLAB is +1. We have to assign a decrement value separately if we want the index value to decrease for a for-loop. If we set a decrement value of -1, the loop will run for 5 times and the final value of i will be -1. No output will be shown due to a semi-colon but the question is what will be the size of i.
 

Tìm kiếm

Back
Top