Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: Elegant way to extract (split) array elements

I have to split, from an array (1D), in blocks of 64, the first element (DC), and another 63 elements (AC) in separate arrays.

I made the UGLY code above:

%split DC from AC
n = 8^2;
DC = zigZagLinha(1 : n : end);
AC = blkproc(zigZagLinha, [1 n],'returnsTheOther63');

;

function array=returnsTheOther63(array64)
    array = array64(2:64);
end

Is there a more elegant way to do this? It's for academic purposes, so, the cleaner, the better.

like image 783
rdlu Avatar asked Dec 17 '25 14:12

rdlu


1 Answers

You can simply reshape it:

res = reshape( zigZagLinha, 64, [] ); % assuming num of elements can be divided by 64 exactly 
% otherwise some padding should be done...
DC = res(1 ,: ); % collect all first elements
AC = res( 2:end, : ); % AC elements
like image 194
Shai Avatar answered Dec 20 '25 07:12

Shai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!