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');

조회 수: 55 (최근 30일)
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

채택된 답변

Steven Lord
Steven Lord 2023년 6월 3일
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.

추가 답변 (1개)

Rumana
Rumana 2023년 9월 5일
Hello I am also facing same..How you have corrected?
  댓글 수: 1
DGM
DGM 2023년 9월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by