I am using isosurface to plot 3d density maps. I would like to plot multiple maps in the same figure, each one with a different color. How can I do so?

조회 수: 5 (최근 30일)
nBins=20;
D=cell(size(A,1),size(A,2));
for i=1:size(A,1)
for j=1:size(A,2)
if ~isempty(A{i,j})
x=A{i,j}(:,1); y=A{i,j}(:,2); z=A{i,j}(:,3);
xBins=linspace(min(x),max(x),nBins);
yBins=linspace(min(y),max(y),nBins);
zBins=linspace(min(z),max(z),nBins);
D{i,j}=zeros(nBins,nBins,nBins);
for ii=1:numel(x)
xi=find((x(ii)>xBins),1,'Last');
yi=find((y(ii)>yBins),1,'Last');
zi=find((z(ii)>zBins),1,'Last');
D{i,j}(xi,yi,zi)=D{i,j}(xi,yi,zi)+1;
end % for ii=1:numel(x)
D{i,j}=smooth3(D{i,j});
%isosurface(D{i,j})
%hold on
end % if ~isempty(A{i,j})
end % for j=1:size(A,2)
end % for i=1:size(A,1)

채택된 답변

Mil Shastri
Mil Shastri 2019년 11월 15일
You can try this:
[x,y,z,v] = flow;
figure;
p = patch(isosurface(x,y,z,v,-3));
p.FaceColor = 'yellow';
hold on;
p = patch(isosurface(x*3,y*1,z*3,v,-3));
p.FaceColor = 'red';
p.EdgeColor = 'none';
p = patch(isosurface(x*1,y*3,z*3,v,-3));
p.FaceColor = 'green';
p.EdgeColor = 'none';
hold off;
%optional
camlight
lighting gouraud
importdata.PNG
  댓글 수: 1
Guy Nir
Guy Nir 2019년 11월 15일
To make it clear, here are the changes I made to the script, following your suggestion - thank you!
%isosurface(D{i,j})
p=patch(isosurface(yBins,xBins,zBins,D{i,j},2)); % MATLAB'sstaff suggestion (Mil Shastri)
p.FaceColor = C(j,:); % I added a colormap (not shown)
p.EdgeColor = 'none';
hold on;

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Mil Shastri
Mil Shastri 2019년 11월 15일
Hi Guy, Please provide a sample for A matrix too. The code doesn't run without it.

Guy Nir
Guy Nir 2019년 11월 15일
I have attached now a sample of the cell array 'A'. I called the sample cell array 'A1', so you would have to rename it as 'A'.
Thank you,
Guy

Guy Nir
Guy Nir 2019년 11월 15일
% Sorry, please use this updated script, otherwise it will plot them all on top of each other.
GridRes=71;
minX=1.2206e+04;
maxX=4.1832e+04;
minY=1.9815e+03;
maxY=39500;
minZ=-913.6920;
maxZ=8.6982e+03;
nBinsX=round((maxX-minX)/GridRes);
nBinsY=round((maxY-minY)/GridRes);
nBinsZ=round((maxZ-minZ)/GridRes);
D=cell(size(A,1),size(A,2));
for i=1:size(A,1)
for j=1:size(A,2)
if ~isempty(A{i,j})
x=A{i,j}(:,1); y=A{i,j}(:,2); z=A{i,j}(:,3);
xBins=linspace(minX,maxX,nBinsX);
yBins=linspace(minY,maxY,nBinsY);
zBins=linspace(minZ,maxZ,nBinsZ);
D{i,j}=zeros(nBinsX,nBinsY,nBinsZ);
for ii=1:numel(x)
xi=find((x(ii)>xBins),1,'Last');
yi=find((y(ii)>yBins),1,'Last');
zi=find((z(ii)>zBins),1,'Last');
D{i,j}(xi,yi,zi)=D{i,j}(xi,yi,zi)+1;
end % for ii=1:numel(x)
D{i,j}=smooth3(D{i,j});
isosurface(D{i,j})
hold on
end % if ~isempty(A{i,j})
end % for j=1:size(A,2)
end % for i=1:size(A,1)
axis equal

카테고리

Help CenterFile Exchange에서 Scalar Volume Data에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by