How to overlay a surf plot with a 2D matrix

6 visualizaciones (últimos 30 días)
Yoni Verhaegen -WE-1718-
Yoni Verhaegen -WE-1718- el 25 de Jun. de 2022
Respondida: Infinite_king el 2 de Oct. de 2023
Hi all,
I have a 3D matrix (300x178x125) describing the surface of a glacier, which is plotted with the slice command:
clear all
load('glacier.mat')
load('realx.mat')
load('realy.mat')
load('realz.mat')
load('h_deb.mat')
length = 50;
c1 = [204, 255, 255]/255;
c2 = [130, 200, 255]/255;
colors_p = [linspace(c1(1),c2(1),length)', linspace(c1(2),c2(2),length)', linspace(c1(3),c2(3),length)'];
glacier = double(squeeze(glacier));
glacier(glacier==0)=nan; % added line
h = slice(realx,realy,realz,glacier, [], [], 1:size(glacier,1));
set(h, 'EdgeColor','none', 'FaceColor','interp', 'FaceLighting','gouraud')
colormap(colors_p)
colorbar;
xlim([1000 3000])
ylim([0 6000])
zlim([0 125])
caxis([0 40])
daspect([0.5 1 0.1])
view(-142,31)
set(gcf, 'color', 'white')
which then looks like this:
I now want to overlay a 2D matrix (300x178) on the surface of the glacier:
How can I overlay the 2D matrix on top of the glacier surface with 0 put to transparant?
Thanks already
  2 comentarios
Adam Danz
Adam Danz el 25 de Jun. de 2022
It sounds like you want to apply the color mapping of the 2D image to the glacier surface object. Is that correct?
You could use texture mapping; warp might be useful; or it might be as easy as applying CData to the glacier object. Tough to tell without more info.
Yoni Verhaegen -WE-1718-
Yoni Verhaegen -WE-1718- el 25 de Jun. de 2022
@Adam Danz Yes that is correct! I added the corresponding matrices in attachment in case this would make my question clearer. The matrix h_deb is what I would like to show on top of the glacier surface.

Iniciar sesión para comentar.

Respuestas (1)

Infinite_king
Infinite_king el 2 de Oct. de 2023
Hi,
I understand that you want to create a surface plot using the provided 3D matrix 'glacier' and overlay color information from the 2D matrix 'h_deb'.
The 'glacier' matrix contains volume data, so we need to first extract the surface information before we can plot it. To obtain the height information of the surface for each point in the X-Y grid, you can refer the below code snippet.
% for every point (i,j) in x,y grid, we are ..
% finding the index 'k', at which we see first see 'nan', ..
% which means the height of surface at [realx(i), realy(j)] is realz(k)
for i = 1 :300
for j = 1:178
% For every point in x,y grid
height(i,j) = nan; % initializing the height as 'nan'
for k = 1:125
% height of the surface at (i,j) index
if isnan(glacier(i,j,k)) == false
height(i,j) = realz(k);
break;
end
end
end
end
Using this surface information we can plot the surface using ‘surf’ function. The colour information can be passed while plotting the surface. Please refer the below code snippet,
% Create a new figure
figure;
% Plot the surface with the given color information from 'h_deb'
surf(realx, realy, height, h_deb);
For more information on ‘surf’ and ‘slice’ function, refer the following documentation,
  1. https://www.mathworks.com/help/matlab/ref/surf.html
  2. https://www.mathworks.com/help/matlab/ref/slice.html
For more information on colour maps and how to create custom colour maps, refer the following documentation,
  1. https://www.mathworks.com/help/matlab/ref/colormap.html
Hope this is helpful.

Categorías

Más información sobre Surfaces, Volumes, and Polygons en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by