Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Expand
titletestkoe.m
Code Block
titletestkoe.m
koe = [
    93, 91, 200, 25, 37;
    75, 93, 112, 30, 52;
    121, 141, 134, 69, 66;
    32, 133, 118, 39, 111;
    27, 68, 93, 95,  35;
    86, 22, 83, 75, 141;
    91, 88, 120, 93, 95
]; 

 

Videoforklaring (

...

33:

...

23)

Del 1 (5:10)Del 2 (mm14:ss55)Del 3 (mm13:ss18)
Widget Connector
urlhttps://www.youtube.com/watch?v=yhS1CPAtcMI
 
Widget Connector
urlhttps://www.youtube.com/watch?v=BpVGjD7moUc
Widget Connector
urlhttps://www.youtube.com/watch?v=7ohjVvssZKE
 
Introduksjon til problemet, og definisjon av funksjonens ytre. Løsning med for-løkker og preallokering.Løsning med vektorisert kode. 

 

Løsningsforslag

Expand
titleHvis du har prøvd selv, trykk her for å se svaret...
Expand
titleUvektorisert løsning
Expand
titleny_flyplasskoe.m
Code Block
titleny_flyplasskoe.m
function retur = ny_flyplasskoe(koe)
    [n_rad, n_kol] = size(koe);
    retur = zeros(n_rad, n_kol - 1);
    flat_koe = koe(:);
    [~, sortert_paa_tid] = sort(flat_koe);
    pers_med_daarligst_tid = sortert_paa_tid(1:n_rad);
    neste_person = 1;
    for j = 1:n_kol - 1
        for i = 1:n_rad
            % Regn verdien til retur(i, j)
            while ismember(neste_person, pers_med_daarligst_tid)
                neste_person = neste_person + 1;
            end
            retur(i, j) = flat_koe(neste_person);
            neste_person = neste_person + 1;
        end
    end
end
Expand
titleVektorisert løsning
Expand
titleny_flyplasskoe.m
Code Block
titleny_flyplasskoe.m
function retur = ny_flyplasskoe(koe)
    flat_koe = koe(:);
    [~, sortert_paa_tid] = sort(flat_koe);
    [m, n] = size(koe);
    pers_med_best_tid = sortert_paa_tid(m+1:end);
    pers_mgtir = sort(pers_med_best_tid);
    ny_flat_koe = flat_koe(pers_mgtir);
    retur = reshape(ny_flat_koe, m, n-1);
end