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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by