A smoother surfplot, maybe with pchip interpolation
Afficher commentaires plus anciens
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)
Mathieu NOE
le 15 Mai 2023
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
Mohammed Saifuddin Ustad
le 15 Mai 2023
Mathieu NOE
le 15 Mai 2023
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)
Mohammed Saifuddin Ustad
le 22 Mai 2023
Mathieu NOE
le 22 Mai 2023
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]%%%
Mohammed Saifuddin Ustad
le 26 Mai 2023
Mohammed Saifuddin Ustad
le 26 Mai 2023
Mohammed Saifuddin Ustad
le 26 Mai 2023
Mathieu NOE
le 26 Mai 2023
this is a job either for the curve fitting toolbox ( I don't have it) or some available files on the FEX section , like :
Mathieu NOE
le 26 Mai 2023
Mathieu NOE
le 26 Mai 2023
Mathieu NOE
le 28 Juin 2023
Hello
Problem solved ?
would you mind accepting my answer ? thanks !
Catégories
En savoir plus sur Interpolation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!