imagesc color map for gridded value

조회 수: 4 (최근 30일)
Shiba Subedi
Shiba Subedi 2021년 4월 23일
댓글: DGM 2024년 7월 11일
Hi all,
I have a set of three variables of a big data set in a given grid (see below) and I would like to plot Z variables as color scale using imagesc. Could you help me how I can plot?
X = 1:01:5
Y =5:01:8
Z = 1,5,0,10,......
length(X)=length(Y)=length(Z).

답변 (1개)

Ayush
Ayush 2024년 7월 11일
Hi,
To plot the Z variable as a colour scale using "imagesc" in MATLAB, you need to ensure that Z is in a matrix form that corresponds to the grid defined by X and Y. If Z is a vector, you need to reshape it into a matrix that matches the dimensions of the grid defined by X and Y. Refer to an example code below for better understanding:
% Define the variables
X = 1:1:5;
Y = 5:1:8;
Z = [1, 5, 0, 10, 2, 3, 4, 7, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19];
% Ensure Z is reshaped into a matrix form
% Here, assuming Z corresponds to a 5x4 grid
Z_matrix = reshape(Z, [length(Y), length(X)]);
% Plot using imagesc
imagesc(X, Y, Z_matrix);
% Set axis properties
set(gca, 'YDir', 'normal'); % To have Y-axis in the correct direction
colorbar; % Display color scale
xlabel('X-axis');
ylabel('Y-axis');
title('Z variable color scale plot');
For more information on the "imagesc" function, refer to the below documentation:
  댓글 수: 1
DGM
DGM 2024년 7월 11일
This isn't what the question was asking -- at least not directly. Preparing the data is the core of the problem.
As per the question,
length(X) = length(Y) = length(Z)
So all inputs are equal-length vectors specifying scattered data. Simply reshaping Z doesn't work. The data needs to be interpolated onto a grid using griddata() or scatteredInterpolant().

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by