MATLAB Answers

0

How to do this loop?

Asked by Aswin Sandirakumaran on 18 May 2018
Latest activity Answered by Stephen Cobeldick on 18 May 2018

I have a vector A = [4,2,3]

    for 1: 
       do this
    end

how to make this for loop execute as number of times as its value in A. eg: first the for loop should check A(1) = 4 -> so for loop should execute 4 times. second A(2) = 2 -> do the for loop two times. three A(3) = 3 -> do the for loop three times. how to implement this idea?

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Stephen Cobeldick on 18 May 2018

for n = [4,2,3]
    for k = 1:n
        ...
    end
end

  0 Comments

Sign in to comment.