Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ res ] = lab4v10( a )
- %LAB4V10 Finds the (left-)nearest positive to the maximum
- % Accepts 1D arrays, returns index, prints value
- n=length(a);
- amax=-Inf;
- kmax=-1;
- for k=1:n
- if a(k)>amax
- amax=a(k);
- kmax=k;
- end
- end
- kpos=-1;
- for k=kmax-1:-1:1
- if a(k)>0
- kpos=k;
- break
- end
- end
- res=kpos;
- ak=a(res)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement