Azzera filtri
Azzera filtri

how to make 2d colorscale using two 73728X3 matrix

1 visualizzazione (ultimi 30 giorni)
Jinyang
Jinyang il 12 Feb 2024
Modificato: DGM il 26 Feb 2024
i have two matrix,1 and 2, the 2d scalecolor x axis should be 1 matrix, 2 should be y axis, and the third column should influence the color of 2d scalecolor map. Xmin=1000, Xmax=2200, Ymin=1000, Ymax=1600.
i know how to use RGB and contour, but i dont know how to draw 73728x3 matrix.
  4 Commenti
Voss
Voss il 13 Feb 2024
Looks like a surface.
z = peaks();
surface(z,'EdgeColor','none')
colorbar
DGM
DGM il 13 Feb 2024
Modificato: DGM il 26 Feb 2024
The color scale is 1D.
It depends if your X,Y data is scattered or gridded. If it's gridded, you can possibly reshape() the data and use pcolor(). If it's scattered, you can probably do something with griddata() or scatteredInterpolant() to make it into something that can be plotted with pcolor().

Accedi per commentare.

Risposte (1)

Yatharth
Yatharth il 26 Feb 2024
By looking at the image you shared in the comments, I agree with Voss that you can acheive your desired output via "surf" function.
Here is a step by step process.
% Making the peaks and plotting the X,Y,Z values
[X,Y,Z] = peaks(50);
figure
s = surf(X,Y,Z);
% Changing the shading to remove the grid
shading interp
% Adjusting the view to show XY plane only
view(2)
% Changing the color map accoording to your use case
colormap("hot")
% You can also make your custom colormap using this method
% Define the number of steps in the colormap
numSteps = 256;
% Create a matrix where the first column (red) goes from 0 to 1,
% the second column (green) stays at 0,
% and the third column (blue) goes from 1 to 0.
customColormap = [(0:numSteps-1)'/max(numSteps-1,1), ...
zeros(numSteps,1), ...
(numSteps-1:-1:0)'/max(numSteps-1,1)];
% Apply the custom colormap
colormap(customColormap);
% Visualize the custom colormap
colorbar
% Making the black outline similar to your image
hold on;
% Define the value around which you want to create a boundary
boundaryValue = 0.5; % Replace this with your specific value
% Add contour plot (in 3D) to emphasize the boundary value
% The third argument to contour3 is a vector of the levels you want to plot
contour3(X, Y, Z, [boundaryValue boundaryValue], 'LineColor', 'k', 'LineWidth', 2);
I hope this helps!
  1 Commento
DGM
DGM il 26 Feb 2024
Modificato: DGM il 26 Feb 2024
You're ignoring the core problem that the question poses. OP does not have XYZ data presented as 2D arrays. Both surf() and pcolor() expect Z data to be 2D. X, Y, and Z are all column vectors. That suggests that the data is scattered, but there's no guarantee that it is; after all, 73728 has a lot of plausible factor pairs that suggests it could be gridded: 128x576, 144x512, 192x384, 256x288, and so on.
As to whether it's gridded or scattered, nobody knows. OP never provided enough information to know whether it is. Likewise, if it is gridded, we don't know the direction in which it was vectorized, so we can't know how it should be devectorized other than to suggest general approaches using permute() and reshape().
There really isn't a need to use surf() and view(), when you can just use pcolor().

Accedi per commentare.

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by