Question
I need to make DCT image compression in Simulink. Image size by default has 3 dimensions, so I used reshape tool to remove the third dimension. Color Space Conversion tool only accepts 3 dimensional images, so I used reshape again. When I try to run the simulation, I get two following errors: Error in port widths or dimensions. 'Output Port 1' of 'untitled/2-D IDCT' is a [512x512] matrix. Error in port widths or dimensions. 'Input Port 1' of 'untitled/Reshape1' has 786432 elements. This port does not accept the dimensions (or orientation) specified by the input signal. I thought reshape was supposed to accept any matrix as an input.
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 24, 2026
The purpose of Simulink's Reshape block and MATLAB's reshape command is only to "reinterpret" the dimensions (aka size) of the signal/variable. The number of elements is not changed. The values as they would appear in the "flat memory" of the computer would also be unchanged.
Your usage doesn't fit the reshape behavior. Your input to the first reshape block has this many elements.
inputNumel = prod([512,512,3])
inputNumel =
786432
Your desired output has this 1/3 as many elements.
outputNumel = prod([512,512])
outputNumel =
262144
Since you are trying to change then number of elements, the reshape block is throwing an error.
One approach to solve this is to put the following code into a MATLAB Function block
function [Y,Cb,Cr] = splitData(u)
Y = u(:,:,1);
Cb = u(:,:,2);
Cf = u(:,:,3);
end
But there is probably a simpler way to achieve your high level goal using capabilities of Image Processing Toolbox.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related simulink Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →