How to Execute loop continuously based on vector elements

1 view (last 30 days)
I have two vectors >> V=1:12; >> L=[ 3 5 8 10] starting from last element of vector L
for i=1:12 if L==10 V(i)=V(i+2)-10*V(i) .... .. next if L==8 do stuff .. .. if L==5 .. .. if L==3 .. ... .. end how could i do this for all elements of L starting last to first in loop fashion..

Answers (1)

Amith
Amith on 2 Mar 2023
As per my understanding you want to write a code such that a for loop for array ‘v’ goes in forward direction while another array L goes in the reverse direction to do some functions for a particular L, the code below demonstrates it.
V = 1:12;
L = [3 5 8 10];
j = length(L)
for i = V
switch j
case 1
disp('do something 1')
case 2
disp('do something 2')
end
j = j-1;
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!