Question
I am trying to plot the individual pixels of an image on a surface plot, I have converted the image from RGB to grayscale - below is the code I have so far, but I can't get it working yet. I get an error saying 'Data dimensions must agree'. RGB=imread('Corn.png'); gray=rgb2gray(RGB); gray_double=double(gray); Min_pixel=min(min(gray_double)); increment=1; xpoints=0:increment:492; ypoints=0:increment:508; [x,y]=meshgrid(xpoints,ypoints); figure surf(x,y,gray_double)
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 25, 2026
From my understanding you have already done the minimum pixel value part and you are facing problem in plotting the the gray image using surf. Changing your code with the below snippet should solve the error.
%increment=1; xpoints=1:size(gray_double,2); ypoints=1:size(gray_double,1); [x,y]=meshgrid(xpoints,ypoints); figure surf(x,y,gray_double)
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 MATLAB Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →