Finding values within a 3D Array

조회 수: 12 (최근 30일)
Tianchu Lu
Tianchu Lu 2024년 4월 16일
편집: Rupesh 2024년 4월 30일
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
Tianchu Lu
Tianchu Lu 2024년 4월 24일
So now I used griddedInterpolant function within Matlab and it worked. than you Chunru for the suggestion
Rupesh
Rupesh 2024년 4월 30일
편집: Rupesh 2024년 4월 30일
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!

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

채택된 답변

Tianchu Lu
Tianchu Lu 2024년 4월 24일
The use of griddedInterpolant to solve the issue.
For more information check out the matlab page.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by