Extract slice data from 3D scalar field into a N by M array for integration in Matlab
2 views (last 30 days)
Show older comments
I am looking to extract data on a plane of a scalar field in Matlab so that I can integrate over the area of the slice and find the average quantity.
Is it possible to use the slice tool in Matlab to get the 3D data that intersects with my slice into an N*M array, where each index represents the location in space? My goal is to eventually integrate over the surface (the slice) to find the average value of the scalar quantity.
I know that I can call a vector of handles h = slice(...) but I'm not very familiar with the slice tool, so I don't know what to input and then what handles will be useful.
Also, I would like to define my slice by 4 vertices a,b,c, and d which I have already defined. Is this possible or do I need to input 3 'position' vectors that define the location of each edge of my slice?
Thanks in advance!
0 Comments
Answers (2)
Walter Roberson
on 12 Nov 2016
No. slice does not generally extract rectangular matrices of data because generally you are using a projection that is oblique relative to one or more of the major axes.
In the particular case where you are wanting to find a cuboid sub-volume, figure out the bounding array indices and use array indexing. For example,
row_a = find(vector_of_x >= a, 1, 'first');
row_b = find(vector_of_x <= b, 1, 'last');
and then YourData(row_a : row_b, :, :)
(provided that you have x in rows, which might not be the case as x is generally columns, but you can easily adapt.)
0 Comments
See Also
Categories
Find more on Matrices and Arrays 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!