How can i plot pressure in polar coordinate with only values in one direction, and then transforming the system into cartesian.
2 次查看(过去 30 天)
显示 更早的评论
- I have values of pressure in one direction (r=0:20:10,000, theta=0)
so i have data of pressure in 1 direction only, since this are poin source i can assure that the distribution in all direction are the same. so i would like to kind of sweep these value to all direction, the ilustration is given as following
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/951464/image.png)
- how to change the system into cartesian so the p that assigned to the exact same location still hold
what i have done so far :
%step 1 : preparing the meshgrid (sample only \pi step)
dr=0:20:10000;
dt=0:pi/2:2*pi;
[theta,rho] = meshgrid(dt,dr);
%step 2 : read pressure
p_init=readtxt(fname,SR,SC,ER,EC); %just some files containing pressure data from 0 to 10,000 with stepsize of 20
p(:,1)=p_init; % i am assign the same value to these 3
p(:,2)=p(:,1); % "sample" direction that later on will be used as
p(:,3)=p(:,1); % the base for interp2
%step 3 : interp2 those pressure into 1\deg angle-step (query angle)
dt_new=0:pi/180:2*pi;
[thetaq,rhoq] = meshgrid(dt_new,dr);
pq=interp2(theta,rho,p,thetaq,rhoq); %query pressure value at the query angle
%step 4 : transform from polar to cartesian using pol2cart
[xq,yq,pq]=pol2cart(thetaq,rhoq,pq);
localpressure=pq;
0 个评论
回答(1 个)
Ayush Modi
2024-1-19
Hi Mahardika,
I understand you would like to interpolate the pressure values to a grid. You can achieve this using interp1 function. interp1 function is suitable for this purpose because, pressure data is a set of one-dimensional data points. Here is an example to demonstrate how you can acheive this:
% Create a Cartesian grid
[X, Y] = meshgrid(-10000:20:10000, -10000:20:10000); % Adjust the range and step size as needed
% Calculate the radial distance for each point on the Cartesian grid
R = sqrt(X.^2 + Y.^2);
% Interpolate the pressure values at each radial distance in R
% P is the pressure data
% r is the radial distance vector
PCartesian = interp1(r, P, R, 'linear', 'extrap');
Note - The grid size and spacing can be changed as per the requirement.
Please refer to the following MathWorks documentation for more information on the interp1 function:
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cartesian Coordinate System Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!