interp2 after rotation around the z-axis

1 view (last 30 days)
sahar kheibarihafshejani
sahar kheibarihafshejani on 29 Mar 2021
Answered: Nipun on 14 May 2024
I do appreciate anybody's help on this problem.
I have 3 big matrixes (1080*1920) two is grid line for my fx ,fy and one representing the angular spectrumA(fx,fy) in the complex form for each fx, fy. these are all define in x'y'z' coordinate system. both fx, fy are in meshgrids that have a regular sampling interval.
Now I apply the 2d rotation around the y and z coordinate system to my matrixes to have fx" ,fy" and their corresponding the angular spectrumA" in x"y"z" coordinate system.
After rotation, the sampling intervals are not regular anymore. in hre I need to use interp2(fx",fy",A",fx_new,fy_new) to define a new uniform sampling interval with this function:
A_new = interp2(fx",fy",A",fx_new,fy_new);
the problem is i recieve"Grid arrays must have NDGRID structure." error since all my fx", fy",A" are not in NDGRID form. can please anybody help me what should i do?
  4 Comments
Jan
Jan on 24 Apr 2021
There is no interpol2 function in Matlab. I cannot find a link concerning "NGDR form" also. So please post, which function you mean and a copy of the complete error message.

Sign in to comment.

Answers (1)

Nipun
Nipun on 14 May 2024
Hi Sahar,
I understand that you intend to apply a 2D rotation around the y and z coordinate systems to your matrices, which include fx, fy, and an angular spectrum A defined in a x'y'z' coordinate system. After rotation, these matrices, now represented as fx", fy", and A", no longer have a regular sampling interval due to the distortion introduced by the rotation. To address this, you are planning to use interp2 to interpolate A" onto a new grid with uniform sampling intervals, but you are encountering a "Grid arrays must have NDGRID structure" error since your rotated grids do not conform to the expected structure for interp2.
To resolve this issue and successfully perform the interpolation, you should follow these steps:
1. Create a New Regular Grid for Interpolation
First, you need to define a new, regular grid (fx_new, fy_new) that covers the range of your rotated coordinates. This grid should have the desired resolution for your interpolated data.
% Example: Define the boundaries and resolution of the new regular grid
x_min = min(fx(:));
x_max = max(fx(:));
y_min = min(fy(:));
y_max = max(fy(:));
% Define the resolution of the new grid, possibly matching the original
fx_new = linspace(x_min, x_max, size(fx, 2));
fy_new = linspace(y_min, y_max, size(fy, 1));
[FX_new, FY_new] = meshgrid(fx_new, fy_new);
2. Flatten the Rotated Grids and Data for interp2
Since your rotated grids (fx", fy") and the data (A") are no longer structured in a regular grid format, you need to flatten them into vectors. This allows interp2 to process them along with your newly defined regular grid.
% Flatten the rotated grids and data into vectors
fx_flat = fx(:);
fy_flat = fy(:);
A_flat = A(:);
% Execute the interpolation on the new, regular grid
A_new = interp2(fx_flat, fy_flat, A_flat, FX_new, FY_new, 'linear'); % You can select an appropriate interpolation method ('linear', 'cubic', etc.)
3. Reshape A_new if Necessary
After performing the interpolation, A_new will conform to the dimensions of your new regular grids (FX_new and FY_new). If you require A_new in a specific shape, you might need to reshape it accordingly, although this step is typically not necessary if FX_new and FY_new are generated with the correct dimensions in mind.
By following these steps, you effectively address the "Grid arrays must have NDGRID structure" error by converting your rotated grids and data into a format compatible with interp2, enabling you to interpolate the rotated data onto a new grid with uniform sampling intervals.
Hope this helps.
Regards,
Nipun

Categories

Find more on 3-D Scene Control in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!