Hi Priyank,
This is a common issue when displaying reshaped image data in MATLAB. The confusion arises because MATLAB’s ‘imagesc’ function, by default, places the (1,1) pixel at the top-left, with the y-axis increasing downwards ('YDir','normal').
To keep the image upright and the y-axis increasing from top to bottom (the MATLAB default), you can flip the image data before displaying, and use 'YDir','normal'. Here’s how you can modify your code:
imagesc(flipud(reshape(Phi(1:r*c,mode), r, c)));
axis image;
colormap(jet); % Optional: for better visualization
colorbar; % Optional: show color scale
set(gca, 'YDir', 'normal'); % Standard y-axis direction (top-to-bottom)
Here ‘flipud()’ flips the image data vertically, correcting any inversion caused during reshaping.
'YDir','normal' ensures the y-axis increases from top to bottom, which is standard in MATLAB.
This is how the output may look like:

For more information, refer the following documentation:

