Advertisement
BORUTO-121

find_submatrix_with_min_sum(dodatni_5)

Mar 10th, 2022
222
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. A=[8 8 10 10; 1 1 2 3;9 2 8 8; 1 2 10 10];%1 2 10 10
  2. disp(A);
  3. %A=[1 1; 2 2]
  4. disp(A')
  5. disp(daj_min(A));
  6. function [B]=daj_min(A)
  7.     [m,n]=size(A);
  8.     %%B=zeros(m/2,n/2);
  9.     T=A';
  10. %     disp(A);
  11. %     disp(T);
  12. %     disp(T(1:0+m/2,1:0+n/2));
  13.    
  14.     suma=sum(sum(T(1:0+m/2,1:0+n/2)));
  15.     kol=1,red=1;
  16.    
  17.     for i=1:m/2+1
  18.           for j=1:n/2+1
  19.               tren_suma=sum(sum(T(i:i-1+m/2,j:j-1+n/2)));
  20. %             disp(T(i:i-1+m/2,j:j-1+n/2));
  21. %             disp(tren_suma);
  22. %             fprintf("Sljedeca %d\n",i);
  23.             if(tren_suma<suma)
  24.                 suma=tren_suma;
  25.                 kol=j;red=i;
  26.             end
  27.          end
  28.     end
  29.     %disp(suma);
  30.     B=T(red:red-1+m/2,kol:kol-1+n/2);
  31. end
Advertisement
RAW Paste Data Copied
Advertisement