Advertisement
ALTracer

Lab6v12

Dec 13th, 2016
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.70 KB | None | 0 0
  1. function [ res ] = lab6v12( a )
  2. %LAB6V12 Find the most distant-from-max element located around the maximum
  3. %   Input: 2D array, output: two pairs of coordinates.
  4. %   Prints the elements as well for your convenience.
  5. amax=-inf;
  6. [m,n]=size(a);
  7. for k=1:m
  8.     for l=1:n
  9.         if a(k,l)>amax
  10.             amax=a(k,l);
  11.             amaxk=k;
  12.             amaxl=l;
  13.         end
  14.     end
  15. end
  16. p=max(amaxk-1,1);
  17. q=min(amaxk+1,m);
  18. r=max(amaxl-1,1);
  19. s=min(amaxl+1,n);
  20. adist=-1;
  21. for k=p:q
  22.     for l=r:s
  23.         if abs(a(k,l)-amax)>adist
  24.             adist=abs(a(k,l)-amax);
  25.             adistk=k;
  26.             adistl=l;
  27.         end
  28.     end
  29. end
  30.  
  31. res=[amaxk,amaxl;adistk,adistl];
  32. amax
  33. a2=a(adistk,adistl)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement