for each loop take the increasing position of a vector matlab?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(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!