Filter löschen
Filter löschen

imagesc color map for gridded value

2 Ansichten (letzte 30 Tage)
Shiba Subedi
Shiba Subedi am 23 Apr. 2021
Kommentiert: DGM am 11 Jul. 2024
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).

Antworten (1)

Ayush
Ayush am 11 Jul. 2024
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 Kommentar
DGM
DGM am 11 Jul. 2024
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().

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Particle & Nuclear Physics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by