You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
3D plot help
2 views (last 30 days)
Show older comments
Hi,
I have a row data composed of independent variables x, y, and z and a dependent variable D, and I would like to 3d plot the geometry. Each independent and dependent variable is a 1D array. However, all 3d plotting functions that I am aware of such as isosurface require 3D arrays. My question is how I can transfom the different arrays into 3d arrays, given that they are not uniform.
21 Comments
Walter Roberson
on 27 Aug 2019
griddata() .
Or possibly you could
ux = unique(x);
uy = unique(y);
uz = unique(z);
D3 = reshape(D, length(ux), length(uy), length(uz));
and then isosurface() on D3
Diab Abueidda
on 27 Aug 2019
Thanks, Walter for the reply.
I did as you suggested:
ux = unique(x);
uy = unique(y);
uz = unique(z);
D3 = reshape(D, length(ux), length(uy), length(uz));
and received the following error
Error using reshape
To RESHAPE the number of elements must not change.
Error in IsoSurface (line 12)
D3 = reshape(D, length(ux), length(uy), length(uz));
Also, I don't think unique function is what I need. In my case, x, y, and z are three spatial coordinates. Hence, some data points will share one or two coordinates, but the remaining coordinates will be different. In this sense, I don't have a problem of nonuniqueness.
Walter Roberson
on 27 Aug 2019
Edited: Walter Roberson
on 28 Aug 2019
Your original line about "Each independent and dependent variable is a 1D array." was not clear. If each one is a 1D array, then that would imply that the variables are independent and that you have all combinations of values available. If that is not the case, then see griddata() that I mentioned before.
Diab Abueidda
on 28 Aug 2019
Thanks, Walter for the reply.
I think griddata is in the right direction, but still I am not getting what I am expecting. The code I am using is
D = xval;
minv= 0; maxv=10; inc=0.05;
[xq,yq,zq]=meshgrid(minv:inc:maxv,minv:inc:maxv,minv:inc:maxv);
Dq = griddata(x,y,z,D,xq,yq,zq,'linear');
margin = 0.1;
xb_index = [find(xq<=minv+margin) find(xq>=maxv-margin)];
yb_index = [find(yq<=minv+margin) find(yq>=maxv-margin)];
zb_index = [find(zq<=minv+margin) find(zq>=maxv-margin)];
cutoff = 0.5;
Dq(xb_index)=cutoff;
Dq(yb_index)=cutoff;
Dq(zb_index)=cutoff;
p1 = patch(isosurface(xq,yq,zq,Dq, cutoff),'FaceColor','blue','EdgeColor','none');
% p2 = patch(isocaps(xq,yq,zq,Dq, cutoff+0.1),'FaceColor','cyan','EdgeColor','none');
view(3);
axis tight
camlight
lighting gouraud
daspect([1,1,1])
isonormals(Dq,p1)
If I use 'nearest' for griddata I get this,
I get what I need as a closed geometry, but it is not smooth. I changed the method to natural. I started getting a bit smoother isosurface, but I could not close the sides of the geometry. Please see below
Any recommendation?
Walter Roberson
on 28 Aug 2019
Please show
scatter3(x, y, z)
Diab Abueidda
on 28 Aug 2019
Hi Walter,
Here it is
Diab Abueidda
on 29 Aug 2019
Hi Walter,
Any thoughts?
Thanks a lot
Walter Roberson
on 29 Aug 2019
I think I will need the data to play with. It is not obvious from the scatter plot that any semi-regular structure exists inside that at all.
Diab Abueidda
on 31 Aug 2019
Hi Walter,
Please find the spatial coordinates attached.
Many thanks!
Walter Roberson
on 31 Aug 2019
I will need the D as well.
I was correct in my original speculation that you have a regular 3D grid of data.
Diab Abueidda
on 31 Aug 2019
Hi Walter,
Thanks for the reply. Please find the data attached.
The data I sent indeed has a regular 3D grid, but please note that this is the simplest case I have, and it is the only one with a regular grid. What I am trying to write is a code that is applicable for all cases, and I am still failing to obtain the geometry even with the simplest case.
Thanks for the support.
Diab Abueidda
on 1 Sep 2019
Hi Walter,
Did you have the chance to check it out?
Many thanks!
Walter Roberson
on 1 Sep 2019
I did have a look, but I couldn't figure out why I was getting the visuals that I was getting.
One thing I do not understand is why you assign 0.5 to locations in the margins, considering that the value distribution is "a lot of values near 0.1" and "a lot of values near 0.9" together with an equal but much smaller distribution of values in-between. It would seem more natural to assign 0 or nan to the margin.
Diab Abueidda
on 1 Sep 2019
Hi Walter,
Thanks for having a look. The values are obtained mathematically by using an optimization framework. Physically, the densities should be binary (zero or one), but we relax this condition and apply penalization to push the density either to zero or one. For numerical stability purposes, we put a minimum value for densities to be 0.001.
Regarding the assigned threshold, any value from 0.3 to 0.7 should be physically acceptable. Feel free to change it.
I hope this gives you an overview of the problem.
Walter Roberson
on 1 Sep 2019
When I look at the data with a 3D visualizer, I can see that there is something that is roughly X shaped, and I do not see anything special happening in the margins. I do not understand why a higher cutoff is being assigned than the values.
If you let H be high values near 0.9, and L be low values near 0.01 then you get a shape that near the top is roughly
HHLLLLLLLLHH
LHHLLLLLLHHL
LLHHLLLLHHLL
LLLHHLLHHLLL
LLLLHHHHLLLL
and I do not understand why you want to modify that to
MMMMMMMMMMMM
MHHLLLLLLHHM
MLHHLLLLHHLM
MLLHHLLHHLLM
MLLLHHHHLLLM
This introduces a "flange" into the visuals that I do not see a purpose for.
Diab Abueidda
on 1 Sep 2019
I added this part to close the isosurface at the boundaries. Otherwise, I would get two isosurfaces as shown in the second figure I shared. I believe that this part I added closed the geometry as portrayed in Figure 1. Is there a better way to close the geometry? I tried to use isocaps as shown in the shared code, but still I had the same problem.
Diab Abueidda
on 2 Sep 2019
Hi Walter,
Regardless of the code I wrote, how would you do it? Basically, I need to get something similar to figure 1 but with smoothed isosurface.
Thanks
Diab Abueidda
on 3 Sep 2019
Hi Walter,
I hope you have an idea of what I am trying to do. Please let me know if you have any ideas/suggestions. I have been stuck with this issue for a while, and your help is highly appreciated.
Thanks
Walter Roberson
on 5 Sep 2019
Sorry, nothing yet, I have been a bit busy.
Diab Abueidda
on 5 Sep 2019
No worries, take your time.
Many thanks
Diab Abueidda
on 10 Sep 2019
Hi Walter,
Any thoughts?
Thanks
Accepted Answer
Thomas Satterly
on 10 Sep 2019
If you're expecting the independant variables X, Y, and Z to make some nice looking 3D surface, you can use Delaunay Triangulation to make a best guess at what that surface would look like and set the corresponding vertex colors to a colormap scaled by dependant variable D. However, you have to be careful about extrapolating data between points using this approach, as the edges generated by triangulation are purely ficticious.
If there is no expected surface between the independant variables, I'd recommend using a 3D scatterplot of X, Y, and Z with the point colors or size determined by dependant variable D. This might be harder to visualizes than a surface, since there's not as strong of relational queues to nearby points, but it does eliminate some misleading extrapolation that generating a surface would cause.
1 Comment
Diab Abueidda
on 17 Oct 2019
Thanks a lot, Thomas!
It worked.
More Answers (0)
See Also
Categories
Find more on Volume Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)