Finding values within a 3D Array

61 visualizzazioni (ultimi 30 giorni)
Tianchu Lu
Tianchu Lu il 16 Apr 2024 alle 11:03
Modificato: Rupesh circa 9 ore fa
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 Commenti
Tianchu Lu
Tianchu Lu il 24 Apr 2024 alle 20:16
So now I used griddedInterpolant function within Matlab and it worked. than you Chunru for the suggestion
Rupesh
Rupesh circa 9 ore fa
Modificato: Rupesh circa 9 ore fa
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!

Accedi per commentare.

Risposta accettata

Tianchu Lu
Tianchu Lu il 24 Apr 2024 alle 20:16
The use of griddedInterpolant to solve the issue.
For more information check out the matlab page.

Più risposte (0)

Categorie

Scopri di più su Interpolation of 2-D Selections in 3-D Grids in Help Center e File Exchange

Tag

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by