About 3,380,000 results
Open links in new tab
  1. for - for loop to repeat specified number of times - MATLAB

    To programmatically exit the loop, use a break statement. To skip the rest of the instructions in the loop and begin the next iteration, use a continue statement. Avoid assigning a value to the index variable within the loop statements. The for statement overrides …

  2. Loop Control Statements - MATLAB & Simulink - MathWorks

    for statements loop a specific number of times, and keep track of each iteration with an incrementing index variable. For example, preallocate a 10-element vector, and calculate five values: x = ones(1,10); for n = 2:6 x(n) = 2 * x(n - 1); end

  3. Loops and Conditional Statements - MATLAB & Simulink

    while loop to repeat when condition is true: try, catch: Execute statements and catch resulting errors: break: Terminate execution of for or while loop: return: Return control to invoking script or function: continue: Pass control to next iteration of for or while loop: pause: Stop MATLAB execution temporarily: parfor: Parallel for-loop: end

  4. while - while loop to repeat when condition is true - MATLAB

    If you inadvertently create an infinite loop (that is, a loop that never ends on its own), stop execution of the loop by pressing Ctrl+C. If the conditional expression evaluates to a matrix, MATLAB evaluates the statements only if all elements in the matrix are true (nonzero).

  5. How do I create a for loop in MATLAB? - MATLAB Answers

    Mar 5, 2012 · A basic for loop in MATLAB is often used to assign to or access array elements iteratively. For example, let’s say you have a vector A, and you want to simply display each value one at a time: A = [3 6 9 4 1];

  6. colon - Vector creation, array subscripting, and for-loop iteration ...

    When you create a vector to index into a cell array or structure array (such as cellName{:} or structName(:).fieldName), MATLAB returns multiple outputs in a comma-separated list. For more information, see How to Use Comma-Separated Lists .

  7. if - Execute statements if condition is true - MATLAB - MathWorks

    Loop through the matrix and assign each element a new value. Assign 2 on the main diagonal, -1 on the adjacent diagonals, and 0 everywhere else.

  8. break - Terminate execution of for or while loop - MATLAB

    The break statement exits a for or while loop completely. To skip the rest of the instructions in the loop and begin the next iteration, use a continue statement. break is not defined outside a for or while loop. To exit a function, use return.

  9. continue - Pass control to next iteration of for or while loop

    It skips any remaining statements in the body of the loop for the current iteration. The program continues execution from the next iteration. continue applies only to the body of the loop where it is called. In nested loops, continue skips remaining statements only in the body of the loop in which it occurs.

  10. Generate Variable Names with a Loop - MATLAB Answers

    Aug 14, 2013 · fix your loop iterator: the loop iterates over k, but inside the loop you refer only to i (which is undefined in your code, but presumably is defined in the workspace, thus also illustrating why experienced MATLAB users avoid scripts for reliable code).

Refresh