Contour plot using Griddata for a curved geometry

4 visualizzazioni (ultimi 30 giorni)
Shaun Burden
Shaun Burden il 24 Giu 2022
Risposto: Ayush il 29 Ago 2023
Hi,
I am trying to plot my velocity on a 2d plane, taken from a slice of my simulation results, I've already extracted the data on the slice, (v_r(y,z)) however when I plot it via griddata the interpolations causes a strightline, where there should be a curve, I thought about making the points lying outside the curve values NaN using inpolygon although have had no success as of yet. Could anyone advise on how to overcome this problem ?
This is the code i've used to plot the slice. Thank you for any help
clc
clear all
WMLES = importdata('30DegreePSyz.xlsx');
variables_names = WMLES.colheaders;
WMLES_data = array2table(WMLES.data,'VariableNames',variables_names);
z = WMLES_data.z;
y = WMLES_data.y;
ps = WMLES_data.ps;
spacing = 1000;
zi = linspace(min(z), max(z), spacing);
yi = linspace(min(y), max(y), spacing);
[zm,ym] = meshgrid(zi, yi);
WFm = griddata(z,y,ps, zm, ym,'cubic');
figure (1)
pcolor(zm, ym, WFm)
shading interp;
colormap('jet');
% xlim([-0.01 0.14])
% ylim([0.18 0.26])
caxis([0 1])
colorbar
colorbar('Ticks',[0 1])

Risposte (1)

Ayush
Ayush il 29 Ago 2023
Hi Shaun,
It is my understanding that you are unable to plot a curve in your contour plot using the griddata function. It is currently resulting to an interpolation that causes a straight line.
Here are some possible workarounds to resolve this issue:
1. Use a higher resolution for the grid, by increasing the value of spacing to get a finer grid which would facilitate more points and accuracy. You can refer to the below documentation to know more about the linspace function:
2. Use a different interpolation method. Try using “linear” or natural as it may provide different results. Experiment with them to choose which one works best for your data. You can refer to the below documentation to know more about the “method” parameter:
3. To exclude points outside the curve from interpolation by setting their values “NaN, you need to do it before the “griddata” function using the inpolygon function. You can refer to the documentation to know more about the “inpolygon” function:
Here is the code snippet to perform the same:
% Define the polygon that encloses the desired curve
x_polygon = [x1, x2, x3, ...]; % x-coordinates of the polygon vertices
y_polygon = [y1, y2, y3, ...]; % y-coordinates of the polygon vertices
% Determine points lying outside the curve
outside_curve = ~inpolygon(z, y, x_polygon, y_polygon);
% Set values outside the curve to NaN
ps(outside_curve) = NaN;
% Perform interpolation
WFm = griddata(z, y, ps, zm, ym, 'cubic');
Hope it helps,
Regards,
Ayush Misra

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by