how to use the loop for?
1 次查看(过去 30 天)
显示 更早的评论
i would like to use the loop for that looks for the maximum of a vector and its position without using the 'max.can anyone help me ?
3 个评论
采纳的回答
KL
2017-11-21
you have got it almost right, you just need to put them inside the loop. I'll give you some tips to work further.
- first assign the first value of the vector to maxi and set indice to 1.
maxi = x(1);
indice = 1;
- then loop through number of elements of x starting from 2 (since we have assigned first value of x to maxi),
for k=2:numel(x)
if(x(k)>maxi)
%and the remainig logic
end %end of if
end %end of for
- in your if else condition, you do not have to assign maxi=maxi for the else case, you can simply write continue;. This will continue to the next iteration.
更多回答(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!