A smoother surfplot, maybe with pchip interpolation

hello everyone,
I have made a surfplot using linear interpolation with x,y,z data from a csv. However i want to make the plot smoother. I have tried cubic interpolation and it does make it better. However i have heard that pchip would make it even smoother, though i have not been able to use that. So looking for a way to utilise pchip or any other interpolation method to make my surfplot smoother. and yes i am aware that increasing N would make it better, but looking for other ways.
T1 = readtable('solarcol3.csv');
VarNames = T1.Properties.VariableNames;
x = T1{:,1};
y = T1{:,2};
z = T1{:,3};
[Ux,iax,ixx] = unique(x);
[Uy,iay,ixy] = unique(y);
N = 25;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym, 'cubic'); % specify cubic interpolation
figure
surfc(Xm, Ym, Zm)
colorbar
grid on
xlabel('Wind Velocity (m/s)')
ylabel('Heat Flux (W/m2)')
zlabel('Mass Flow Rate (kg/s)')

Réponses (1)

hello
I used this excellent FEX submission to get this result :
T1 = readtable('solarcol3.csv');
VarNames = T1.Properties.VariableNames;
x = T1{:,1};
y = T1{:,2};
z = T1{:,3};
[Ux,iax,ixx] = unique(x);
[Uy,iay,ixy] = unique(y);
N = 25;
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym, 'cubic'); % specify cubic interpolation
Zm = smoothn(Zm,1000); % Fex : https://fr.mathworks.com/matlabcentral/fileexchange/25634-smoothn?s_tid=ta_fx_results
figure
surfc(Xm, Ym, Zm)
colorbar
grid on
xlabel('Wind Velocity (m/s)')
ylabel('Heat Flux (W/m2)')
zlabel('Mass Flow Rate (kg/s)')

11 commentaires

Hey thanks so much, that works beautifully. Also is the picture that you uploaded for s=1000? because mine looks a different, plus the formatting of your axis text is different too. Can you also upload your .fig file. thanks
hello again
yes the picture was done with s = 1000 as in the code I posted
now you can of course adapt s to your own taste
fyi the fig (with s = 1000) in attachment)
hey thanks so much, that works beautifully. however is there any way to specifically set the aspect ratio of the window/plot. i wanted a 5:3 ratio, width:height that is. any way to set that?
hello again
yes you can specify the size and position of any figure , like in this example :
%%%Matlab convention [left bottom width height]%%%
set(0,'Units','Pixels');
scrsz = get(0,'ScreenSize');
scr_width = scrsz(3);
scr_heigth = scrsz(4);
% create a large 5/3 format figure
height = scr_heigth/1.25;
width = 5/3*height;
left = (scr_width - width)/2;
bottom = (scr_heigth - height)/2;
f = figure('Position', [left bottom width height]); %%%Matlab convention [left bottom width height]%%%
heyy thanks veryy muchh
any idea how to make an equation out of my xyz data??
i want to solve for z inserting x and y
or maybe i can formulate an equation from the 3D plot
Hello
Problem solved ?
would you mind accepting my answer ? thanks !

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interpolation dans Centre d'aide et File Exchange

Produits

Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by