Advertisement
ALTracer

lab4v10

Dec 14th, 2016
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.37 KB | None | 0 0
  1. function [ res ] = lab4v10( a )
  2. %LAB4V10 Finds the (left-)nearest positive to the maximum
  3. %   Accepts 1D arrays, returns index, prints value
  4. n=length(a);
  5. amax=-Inf;
  6. kmax=-1;
  7. for k=1:n
  8.     if a(k)>amax
  9.         amax=a(k);
  10.         kmax=k;
  11.     end
  12. end
  13. kpos=-1;
  14. for k=kmax-1:-1:1
  15.     if a(k)>0
  16.        kpos=k;
  17.         break
  18.     end
  19. end
  20. res=kpos;
  21. ak=a(res)
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement