imagesc color map for gridded value

2 次查看(过去 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 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by