diff --git a/SRtoLF.m b/SRtoLF.m
index 2da2a15ba99dd75ab5fce96c1dc532c8f2bac413..e73dd15a4e49ef69a812a847aace374096716d82 100644
--- a/SRtoLF.m
+++ b/SRtoLF.m
@@ -25,13 +25,19 @@ order = p.Results.order;
 relative = p.Results.relative;
 
 if isnumeric(dispX)
-    dispX = num2cell(dispX);
+    dispXcell = num2cell(dispX);
     relative = true;
+else
+    dispXcell = dispX;
+    dispX = cell2mat(dispX);
 end
 
 if isnumeric(dispY)
-    dispY = num2cell(dispY);
+    dispYcell = num2cell(dispY);
     relative = true;
+else
+    dispYcell = dispY;
+    dispY = cell2mat(dispY);
 end
 
 %% Initialize constants
@@ -73,7 +79,13 @@ end
 [LFVal,LFDisp,LFLab,LFBuf] = deal(nan(LFSize));
 LFSet = SR.FieldsToSet(LFVal,LFSize,LFPos,LFDisp,LFLab);
 
-disps = [SRDisp{:}]; 
+switch order
+    case 'ascend'
+        disps = max([dispX;dispY],[],1);
+    case 'descend'
+        disps = min([dispX;dispY],[],1);
+end
+
 [~,sortedLab] = sort(disps,order);
 
 %% Build lightfield
@@ -103,8 +115,8 @@ for lab = sortedLab
     ygv = reshape(1:SRSize(4),1,1,1,[]);
     
     if relative
-        dispX{lab} = (ugv-uref).*dispX{lab};
-        dispY{lab} = (vgv-vref).*dispY{lab};
+        dispXcell{lab} = (ugv-uref).*dispXcell{lab};
+        dispYcell{lab} = (vgv-vref).*dispYcell{lab};
     end
 
     % Mask corresponding to query points inside super-ray boundary
@@ -153,8 +165,8 @@ for lab = sortedLab
     
     % Perform disparity compensation if necessary
     if ~dispComp
-        SRX = SRX+dispX{lab};
-        SRY = SRY+dispY{lab};
+        SRX = SRX+dispXcell{lab};
+        SRY = SRY+dispYcell{lab};
     end
     
     % Super-ray (query) coordinates (4D)