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

조회 수: 3 (최근 30일)
DulceEien
DulceEien 2021년 8월 9일
편집: DulceEien 2021년 8월 9일
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

채택된 답변

Adam Danz
Adam Danz 2021년 8월 9일
편집: Adam Danz 2021년 8월 9일
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
DulceEien
DulceEien 2021년 8월 9일
편집: DulceEien 2021년 8월 9일
thank you for the answer, I will add L with the same length

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by