About 8,790,000 results
Open links in new tab
  1. for

    for index = values, statements, end executes a group of statements in a loop for a specified number of times. values has one of the following forms: initVal : endVal — Increment the index variable from initVal to endVal by 1 , and repeat execution of …

  2. Can I use a vector as index variable for a loop? - MATLAB

    Oct 4, 2016 · Well, you can't use loop variable that way. You can use nested for loop to assign new loop variable for the inner for loop. For example :

  3. How to Index Through a For Loop - MATLAB Answers

    Jul 4, 2010 · How to Index Through a For Loop. Learn more about indexing, for loops, row vectors, incrementing, for loop, nested for loop, nesting.

  4. indexing for loop matlab - Stack Overflow

    Feb 19, 2016 · In a for loop statement you can basically write any row vector and the index takes those values. For example. disp(i); % prints 1,7,11,14,23. This is true for arrays of objects, cell arrays, basically any single row matrix. Thank you works perfectly!!

  5. Using vector elements as for index in Matlab - Stack Overflow

    Jan 24, 2014 · Just use stored_val = i inside the loop to get the current value. In a nested process, each outer-loop variable exists in all the inner-ones. So, inside the inner-most loop do i_all = [i1, i2, i3] and pass this as input to the function. Also, avoid the use of i and j as any type of variable in MATLAB (See: Using i and j as variables in Matlab)

  6. Best practice for MATLAB for loop index - Stack Overflow

    Jun 14, 2013 · valArray: creates a column vector index from subsequent columns of array valArray on each iteration. For example, on the first iteration, index = valArray(:,1). The loop executes for a maximum of n times, where n is the number of columns of valArray, given by numel(valArray, 1, :).

  7. How to Loop Through Vector in MATLAB - Delft Stack

    Feb 2, 2024 · The while loop in MATLAB provides a flexible way to iterate through a vector by incrementing an index until a specific condition becomes false. This condition is often based on the length of the vector or other logical criteria.

  8. Lecture 10: MATLAB - loops and vectorization - CDS) Lab

    Iterating over vectors, matrices, and cell using for-loops. Note that the index of for-loop must not necessarily be an integer. Basically you can use the for-loop index to iterate over anything that is iterable in MATLAB. For example, consider the following, a = [1,0,2,3,7,-1]; for index = a disp(class(index)) disp(index) end

  9. Indexing Arrays within a for loop - MATLAB Answers

    Mar 18, 2021 · Using the for loop which computates the random varables R,Vs,tc,C to generate the Vc, I need to create the 100 variable long array A. I don't know why the A is coming out to be a single scalar of 173 and not an array with a bunch of different values that would correspond to the randomness of the 4 random variables.

  10. How do I iterate through each element in an n-dimensional matrix in MATLAB?

    As pointed out in a few other answers, you can iterate over all elements in a matrix A (of any dimension) using a linear index from 1 to numel(A) in a single for loop. There are also a couple of functions you can use: arrayfun and cellfun .

Refresh