Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Videoforklaring (mm:ss)

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

 

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
 

...