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 ?
Best Answer
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 tomaxi and setindice to 1.
maxi = x(1);
indice = 1;
then loop through number of elements of x starting from 2 (since we have assigned first value ofx tomaxi),
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 assignmaxi=maxi for the else case, you can simply writecontinue;. This will continue to the next iteration.
Best Answer