Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ res ] = lab6v12( a )
- %LAB6V12 Find the most distant-from-max element located around the maximum
- % Input: 2D array, output: two pairs of coordinates.
- % Prints the elements as well for your convenience.
- amax=-inf;
- [m,n]=size(a);
- for k=1:m
- for l=1:n
- if a(k,l)>amax
- amax=a(k,l);
- amaxk=k;
- amaxl=l;
- end
- end
- end
- p=max(amaxk-1,1);
- q=min(amaxk+1,m);
- r=max(amaxl-1,1);
- s=min(amaxl+1,n);
- adist=-1;
- for k=p:q
- for l=r:s
- if abs(a(k,l)-amax)>adist
- adist=abs(a(k,l)-amax);
- adistk=k;
- adistl=l;
- end
- end
- end
- res=[amaxk,amaxl;adistk,adistl];
- amax
- a2=a(adistk,adistl)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement