diff --git a/read.m b/read.m
index 27c1d4cab36dc1f2ca9ae767e383cce2fbb31145..f85f08560b136d1c89728322e9b7d5c503bfbebd 100644
--- a/read.m
+++ b/read.m
@@ -37,8 +37,8 @@ precision = [writePrecision '=>' readPrecision];
 %% Recover yuv size
 m = utils.getMat(recDir,name,false);
 yuvSize = m.yuvSize;
-imgRes  = yuvSize(1:2);
-imgSize = yuvSize(3:end);
+imgSize = yuvSize(1:3);
+imgRes  = yuvSize(4:end);
 
 %% YUV 400/420/422: define interpolation sampling grids
 [xq,xgv] = deal(1:imgSize(1));
diff --git a/write.m b/write.m
index a1656a103962cb63815042cc818765a23b3436d3..93bdd0705cf72a90074e3b86320ef6b7de3d7257 100644
--- a/write.m
+++ b/write.m
@@ -34,7 +34,8 @@ outColSpace = p.Results.outColSpace;
 
 imgRes  = size(frames);
 imgSize = size(frames{1});
-yuvSize = [imgRes,imgSize];
+imgSize(end+1:3) = 1;
+yuvSize = [imgSize,imgRes];
 
 %% Save parameters to read yuv file back
 m = utils.getMat(refDir,name,true);
@@ -50,7 +51,7 @@ m.bitDepth = bitDepth;
 frames = yuv.convert(frames,outColSpace,inColSpace,bitDepth);
 
 %% Incompatibility (needs better handling)
-if (~strcmp(subSamp,'400')&&numel(imgSize)~=3)
+if (~strcmp(subSamp,'400')&&imgSize(3)~=3)
     error('Incompatible frame size and subsampling');
 end