Error using image Color data must be an m-by-n-by-3 or m-by-n matrix. Error in imagesc (line 52) hh = image(varargin{:}, 'CDataMapping', 'scaled');

28 views (last 30 days)
I dont understandf the problem here I am trying to plot sea velocity, and my EVO matrix is 4-D double, but it wont work. I tried using dimread, but it does not recognize the function
dir = 'C:\Users\Madison-Riley\Downloads\'
ncfile= 'Sea.Velocity.nc'
ncdisp([dir,ncfile]);
lat = ncread([dir,ncfile],'latitude');
lon = ncread([dir,ncfile],'longitude');
NVO = ncread([dir,ncfile], 'vo');
EVO = squeeze(ncread([dir,ncfile], 'uo'));
imagesc(lon,lat,EVO);
colormap jet;
colorbar

Accepted Answer

Steven Lord
Steven Lord on 3 Jun 2023
As the error message says, the image data you pass into imagesc must be a matrix (if it's an indexed image or a grayscale intensity image) or a 3-D array with size 3 in the third dimension (for an RGB truecolor image.) See this documentation page for more information about the image types.
A 4-D array like you have is neither a matrix nor a 3-D array. [You used the term "matrix" in your question, but that has a different meaning in MATLAB than the way you're using it. Your array wouldn't satisfy the requirements of the ismatrix function, so it's not a matrix.] Therefore it is not valid image data for imagesc.
A = ones(4, 4, 3, 6);
ismatrix(A)
ans = logical
0
If your data represents a collection of images, you might want to use the imtile function, create a tiledlayout of axes and display each image from your collection in a different axes using a for loop, or use the montage function from Image Processing Toolbox.

More Answers (1)

Rumana
Rumana on 5 Sep 2023
Hello I am also facing same..How you have corrected?
  1 Comment
DGM
DGM on 6 Sep 2023
OP never provided enough information for any of us to know that you are indeed facing the same error, or whether any particular solution is appropriate.
Since OP is gone, you have to explain exactly what you are trying to do and what error you are getting.
Provide some example code and data. If you can't share real data, you can provide some small amount of placeholder data, or at least appropriate information about the array size and type. If your application is similar to OP's, then it would help to know what quantities are described by the third and fourth dimensions of the main data array.

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!