How to Execute loop continuously based on vector elements
조회 수: 1 (최근 30일)
이전 댓글 표시
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..
댓글 수: 0
답변 (1개)
Amith
2023년 3월 2일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!