for each loop take the increasing position of a vector matlab?

1 visualización (últimos 30 días)
If I have a vector L = [4;5;6] and then a for loop
where x = [11;12;13;14;15]
could I take for each loop the increasing position of L? for example for the first iteration L = 4, the second interation L = 5
for i=1:lenght(x)
if x(i) <(0.01*L)
extent(i) = 'A';
end
end

Respuesta aceptada

Adam Danz
Adam Danz el 9 de Ag. de 2021
Editada: Adam Danz el 9 de Ag. de 2021
The length of L would need to equal the length of x or it could be longer than x, but not shorter.
for i=1:lenght(x)
if x(i) <(0.01*L(i))
% ^^^ add this
extent(i) = 'A';
end
end
--or--
This version works for any length of x
L = 3;
% ^^^^ add this
for i=1:lenght(x)
if x(i) <(0.01*(L+i))
% ^^^^^ add this
extent(i) = 'A';
end
end
  1 comentario
DulceEien
DulceEien el 9 de Ag. de 2021
Editada: DulceEien el 9 de Ag. de 2021
thank you for the answer, I will add L with the same length

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by