ow to convert a 3Dplot to 2D?

3 次查看(过去 30 天)
2NOR_Kh
2NOR_Kh 2022-10-28
编辑: DGM 2022-10-29
I have a code to generating phantom data in MATLAB but my final plot is in 3D. I searched throught mathwork and could find some solutions such as this one:
shading interp % this changes the color shading (i.e. gets rid of the grids lines on the surface)
view(2) % same as view(0, 90)
but this did not work on this plot
This is my code and results:
%1000 points randomly distributed in the square −5mm < 𝑥 < 5mm,
%35mm < 𝑧 < 45mm, y=0. Set the amplitude of the scatterers to 0 if they lie inside a circle of
%radius 2.5 mm centered at x=0, z=40 mm, and to 1 otherwise
clc;
close all;
clear all;
% field_init(-1);
% Create uniform target
% Define volume, number of scatterers
phantom_min_coords=[-5 0 35]*1e-3;
phantom_lengths=[10 0 10]*1e-3;
N_scatterers=1000;
% Generate scatter positions using Matlab’s implicit expansion feature
% (Matlab 2016b or later)
positions=( rand(N_scatterers,3).*phantom_lengths )+phantom_min_coords;
%2.5mm radius cyst centered at (0,0,40)mm:
amplitudes=ones(N_scatterers,1);
for n=1:N_scatterers
if sum((positions(n,:)-[0 0 40]*1e-3).^2)<(2.5e-3)^2
amplitudes(n)=0;
end
end
s=amplitudes==1;
figure,plot3(positions(s,1)*1e3,positions(s,2)*1e3,positions(s,3)*1e3,'b.','MarkerSize',10);
hold on;
s=amplitudes==0;
plot3(positions(s,1)*1e3,positions(s,2)*1e3,positions(s,3)*1e3,'k.','MarkerSize',10);
% shading interp % this changes the color shading (i.e. gets rid of the grids lines on the surface)
% view(2) % same as view(0, 90)
I commented the final two lines of the code, however it did not work for this example.

回答(1 个)

DGM
DGM 2022-10-29
编辑:DGM 2022-10-29
Try this instead.
view([0 1 0])
In this case, the parameter is a unit vector defining the view orientation. You're looking at the y = 0 plane.
Using view(2) is the same as view([0 0 1]), and just gives you a view of the z = 0 plane

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by