# Rotating data using griddata

8 views (last 30 days)
ran on 24 Sep 2023
Commented: Matt J on 25 Sep 2023
I have a tmperature flow data abouve wall with a slop. I want to smooth the data on the wall so i rotated the data using griddata(). now i want to retern to the original palne so i tray the same thing but i get matrix of NaN. do griddata() work with matrixs? any way to fix it? in my code xn yn and Tn are the original data.
theta = -atan2(0.002, 0.005 ); % in degrees
% Calculate the rotated x and y coordinates element-wise
rotated_x = xn.* cos(theta) - yn.* sin(theta);
rotated_y = xn.* sin(theta) + yn.* cos(theta);
num_points = 1000; % Adjust this number as needed
uniqe_x = linspace(min(rotated_x(:)), max(rotated_x(:)), num_points);
uniqe_y = linspace(min(rotated_y(:)), max(rotated_y(:)), num_points);
[X, Y] = meshgrid(uniqe_x, uniqe_y);
% Interpolate the temperature data onto the grid
rotated_T = griddata(rotated_x, rotated_y, Tn, X, Y);
rotated_T = smoothdata(rotated_T,2,'movmean',35);
% Reverse the rotation by using the negative angle
reverse_theta = -theta;
% Calculate the rotated x and y coordinates element-wise
original_x = X .* cos(reverse_theta) - Y .* sin(reverse_theta);
original_y = X .* sin(reverse_theta) + Y .* cos(reverse_theta);
% Interpolate the rotated and smoothed data onto the original grid
original_T = griddata(X, Y, rotated_T, original_x, original_y,'cubic');
contourf(original_x, original_x, original_T)
Warning: Contour not rendered for non-finite ZData

Matt J on 24 Sep 2023
You should probably just use imrotate with the loose option flag.
ran on 25 Sep 2023
Edited: ran on 25 Sep 2023
i use 'cubic' intarpulation in 'griddata()' yes. when i use imrotate the adges of my data get wired, some of my data delleted when i rotate the data in the first place then when i tray to get back i ge exsta data where my data was befor how i fix that????? but i think using imrotate willl be much easer aproch then what i do now.
another problem i have with it that i cant use it to flip the image then flip it back beacuse for some reason it crate the problem again, so all i want to do it to flip it from the 'griddata()' back to the original results without any missing data
Matt J on 25 Sep 2023
Try using imrotate with cubic interpolation.