How to find first 25 coefficients of DCT in Matlab?
In JPEG compression, DCT coefficients are generally parsed not as sub-blocks, but in an order:


  corresponding to the entries in the top left corner


This corresponds to a zigzag indexing:



This can be obtained by the following code. Here I use the $8\times8$ JPEG quantization table, and extracted the $5\times5$ top-left coefficients. On a light note, the bijection between the $2$D coordinates and the zigzag  $1$D coordinate can be obtained by Cantor pairing polynomials (Matlab implementation).

% ExtractComponent
nCoomponent = 25;
quantTable = [    16,  11,  10,  16,  24,  40,  51,  61;
    12,  12,  14,  19,  26,  58,  60,  55;
    14,  13,  16,  24,  40,  57,  69,  56;
    14,  17,  22,  29,  51,  87,  80,  62;
    18,  22,  37,  56,  68, 109, 103,  77;
    24,  35,  55,  64,  81, 104, 113,  92;
    49,  64,  78,  87, 103, 121, 120, 101;
    72,  92,  95,  98, 112, 100, 103,  99];

index = zigzag(length(quantTable));
indexCrop = index(2:26);
quantTableCrop = zeros(size(quantTable));
quantTableCrop(indexCrop) = quantTable(indexCrop);

figure(1)
image(quantTable);
figure(2)
image(quantTableCrop);


and the function

function index = zigzag(size)

% ZIGZAG(size) returns the zigzag order index
% for a size x size square matrix

    index = 1:size*size;
    [j,i] =  meshgrid(1:size);
    i = i(:);
    j = j(:);
    iplusj = i + j;
    even_ind = (rem(iplusj,2) == 0);
    odd_ind = ~even_ind;
    j(even_ind) =   j(even_ind);
    j(odd_ind) =    i(odd_ind);
    [nouse,tags] = sortrows([iplusj,j]);
    index = index(tags);
end