Azzera filtri
Azzera filtri

How to Execute loop continuously based on vector elements

1 visualizzazione (ultimi 30 giorni)
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..

Risposte (1)

Amith
Amith il 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

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by