1function writeYUV420file(filename, Y, U, V) 2% writeYUV420file(filename, Y, U, V) 3 4fid = fopen(filename,'wb'); 5if fid==-1 6 error(['Cannot open file ' filename]); 7end 8 9numFrames=size(Y,3); 10 11for k=1:numFrames 12 % Write luminance 13 fwrite(fid,uint8(Y(:,:,k).'), 'uchar'); 14 15 % Write U channel 16 fwrite(fid,uint8(U(:,:,k).'), 'uchar'); 17 18 % Write V channel 19 fwrite(fid,uint8(V(:,:,k).'), 'uchar'); 20end 21 22fclose(fid); 23