Borrar filtros
Borrar filtros

Finding values within a 3D Array

4 visualizaciones (últimos 30 días)
Tianchu Lu
Tianchu Lu el 16 de Abr. de 2024
Editada: Rupesh el 30 de Abr. de 2024
The problem I have is that I have a 3D array with the dimension of 181x361x1931. If I was to simulate a line at any point through the 3D array, is there a way to retrieve all the data that the simulated line would penetrate through and store them within a new array.
I have seen various answers that deals with a 2D array, but haven't seen anybody answer a question regarding a 3D array. I have also seen that there are various packages on Matlab that deals with Bresenham Line Algorithm in 3D matrix, but like I said the line is imaginary thus, i don;t have much of an idea of how to go about it. I was purely wondering if there is an easier way of doing such calculations.
  5 comentarios
Tianchu Lu
Tianchu Lu el 24 de Abr. de 2024
So now I used griddedInterpolant function within Matlab and it worked. than you Chunru for the suggestion
Rupesh
Rupesh el 30 de Abr. de 2024
Editada: Rupesh el 30 de Abr. de 2024
Hi Tianchu ,
I understand you're looking for a method to simulate a line through a 3D array of dimensions 181x361x1931 in MATLAB and retrieve all data points that this line intersects. To retrieve data points from a 3D array that a simulated line would penetrate through, you can indeed use various approaches, including geometric algorithms and interpolation methods. The “interp3” function in MATLAB can be used for this purpose. Interpolation is a method of estimating values between two known values. “interp3” specifically works with 3D data, making it suitable for your needs.
This approach involves defining the line by its start and end points in the 3D space and then interpolating the values at regular intervals along this line. Below is one sample example to help you understand 3d interpolation in a better way:
% Assuming 'data' is your 3D array
data = rand(181, 361, 1931);
% Define the line's start and end points
startPoint = [1, 1, 1]; % Adjust as necessary
endPoint = [181, 361, 1931]; % Adjust as necessary
% Generate points along the line
numPoints = 1000; % Number of points, adjust based on desired resolution
x = linspace(startPoint(1), endPoint(1), numPoints);
y = linspace(startPoint(2), endPoint(2), numPoints);
z = linspace(startPoint(3), endPoint(3), numPoints);
% Retrieve the values along the line
lineValues = interp3(data, x, y, z, 'linear'); % 'linear' interpolation
The example uses linear interpolation, but MATLAB offers other methods ('nearest', 'cubic', 'spline') depending on your data's nature and your accuracy needs. For more detailed guidance or alternative approaches, you can explore below MATLAB's documentation.
Hope this helps!

Iniciar sesión para comentar.

Respuesta aceptada

Tianchu Lu
Tianchu Lu el 24 de Abr. de 2024
The use of griddedInterpolant to solve the issue.
For more information check out the matlab page.

Más respuestas (0)

Categorías

Más información sobre Interpolation of 2-D Selections in 3-D Grids en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by