Effacer les filtres
Effacer les filtres

How to Execute loop continuously based on vector elements

1 vue (au cours des 30 derniers jours)
Raghavendra Reddy P
Raghavendra Reddy P le 13 Fév 2015
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..

Réponses (1)

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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by