Display three 2D images into 3D space

30 ビュー (過去 30 日間)
Tsuwei Tan
Tsuwei Tan 2021 年 7 月 30 日
編集済み: Adam Danz 2021 年 7 月 31 日
Please dowload all the files and run
disp_data.m
which will generate three 2D images (like "Picture 1.jpg" as attaced) from
data.mat
Please guide me how to change the aspect ratio (combine three 2D images on the same X-Y-Z axes) so basically I can make "Picture 1.jpg" to look like the "Example_pic.jpg" ?
I tried the view angle way but failed. Or I have a create and load one of the 2D images to rotate it and then combine?

採用された回答

Adam Danz
Adam Danz 2021 年 7 月 31 日
編集済み: Adam Danz 2021 年 7 月 31 日
pcolor does not support 3D coordinates so you'll have to use surf with flattened values along one of the dimensions for each plane. Usually the XY plane is at the minimum Z value of the data, the XZ plane is at the max Y value of the data, and the YZ plane is at the max X value of the data.
It's similar to the last example in this answer using marginal 2D histograms.
Judging by the axis labels, it looks like The Cs/Ps plot will be along the XY plane (the floor), H(m) will be along the Z plane so the Ps/H(m) plot will be on the XZ plane and the Cs/H(m) plot will be on the YZ plane or vise versa.
You can easily switch the planes by adjusting the logic demonstracted in the solution below.
The first block of code generates data and was copied and cleaned up from your m-file by removing comments but I haven't looked deeply into it nor have I changed any code. The warnings that appear suggest potentially suboptimal coding.
The second block of code is what you'll want to focus on. I have not judged whether the data are all oriented correctly -- see the second figure below to confirm the projections.
Generate data
% Copied and cleaned up a bit from OP's m-file.
data = load('data.mat');
Population_gen_cum = data.Population_gen_cum;
Score_gen_cum = data.Score_gen_cum;
[Min, index]=min(Score_gen_cum);
H_min=Population_gen_cum(index,1)/10;
cs_min=Population_gen_cum(index,2);
rho_s_min=Population_gen_cum(index,3)/100;
cb_min=Population_gen_cum(index,4);
rho_b_min=Population_gen_cum(index,5)/100;
D_min=Population_gen_cum(index,6)/10;
err_bnd=1; % This is 10_25_40Hz.
%% Create table
indx=Score_gen_cum<=(Min+err_bnd);
H=Population_gen_cum(indx,1)/10;
cs=Population_gen_cum(indx,2);
rho_s=Population_gen_cum(indx,3)/100;
cb=Population_gen_cum(indx,4);
rho_b=Population_gen_cum(indx,5)/100;
D=Population_gen_cum(indx,6)/10;
HH = [min(H); mean(H); max(H)];
css = [min(cs); mean(cs); max(cs)];
rhoss= [min(rho_s); mean(rho_s); max(rho_s)];
cbb = [min(cb); mean(cb); max(cb)];
rhobb= [min(rho_b); mean(rho_b); max(rho_b)];
DD = [min(D); mean(D); max(D)];
%% 3D Picture
Z=Score_gen_cum(indx);
%%
H_xy = linspace(min(H),max(H),1000) ;
cs_xy = linspace(min(cs),max(cs),1000) ;
rhos_xy = linspace(min(rho_s),max(rho_s),1000) ;
[H_X,cs_Y] = meshgrid(H_xy,cs_xy) ;
H_cs_Z = griddata(H,cs,Z,H_X,cs_Y) ;
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Produce plots
figure()
% Plot XY plane
[cs_X,rhos_Y] = meshgrid(cs_xy,rhos_xy) ;
cs_rhos_Z = griddata(cs,rho_s,Z,cs_X,rhos_Y) ;
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
minZ = min(H_X(:)); % Z Coordinates of the XY plane
surf(cs_X, rhos_Y, minZ*ones(size(cs_rhos_Z)), cs_rhos_Z)
hold on
% Add XZ plane where x-axis is C_s(/s)
maxY = max(rhos_Y(:)); % Y Coordinate of XZ plane
surf(cs_Y, maxY*ones(size(H_cs_Z)), H_X, H_cs_Z); % X-Z values switched to match 3D axes
% Add YZ plane where y-axis is P_s
[H_X,rhos_Y] = meshgrid(H_xy,rhos_xy) ;
H_rhos_Z = griddata(H,rho_s,Z,H_X,rhos_Y) ;
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
maxX = max(cs_X(:)); % X Coordinate of YZ plane
surf(maxX*ones(size(H_rhos_Z)), rhos_Y, H_X, H_rhos_Z) % Y-Z values switched to match 3D axes
shading interp ;
colormap jet;
caxis([Min Min+err_bnd])
colormap(flipud(jet))
% Keep surfaces as close to the axis limits
% as possible for easier axis tick referencing
axis tight
box on
xlabel('c_s (m/s)');
ylabel('\rho_s');
zlabel('H (m)')
Verifying results
You may want to look into whatever transformations you're doing because the XZ and YZ planes do not look like projections for the XY plane components. The figure below plots the 3D version of the XY plane and the XY,YZ,XZ surfaces of the same data. The XZ and YZ planes do not look like the XZ ,YZ planes in your code.
figure()
tiledlayout(2,2)
% Plot 3D view
nexttile
sh = surf(cs_X, rhos_Y, cs_rhos_Z, cs_rhos_Z);
shading interp ;
colormap jet;
caxis([Min Min+err_bnd])
colormap(flipud(jet))
xlabel('c_s (m/s)');
ylabel('\rho_s');
zlabel('H (m)')
title('3D view')
ax = nexttile();
copyobj(sh,ax)
view(0,90)
xlabel('c_s (m/s)');
ylabel('\rho_s');
title('XY view')
ax = nexttile();
copyobj(sh,ax)
view(0,0)
xlabel('c_s (m/s)');
zlabel('H (m)')
title('XZ view')
ax = nexttile();
copyobj(sh,ax)
view(90,0)
zlabel('H (m)')
ylabel('\rho_s');
title('YZ view')
  2 件のコメント
Tsuwei Tan
Tsuwei Tan 2021 年 7 月 31 日
Great! Thank you for enlighting me how to do this! This is exactly what I need!
Adam Danz
Adam Danz 2021 年 7 月 31 日
Happy to help. I'll leave it up to you to careful inspect it to confirm that it describes the data correctly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrange についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by