# How can I draw surf 3D shape with matrix data? (MATLAB)

Hi everyone,

I want to draw a 3D shape with the surf command (MATLAB). I have the data I collected and its data is contained in the Matlab code. I was able to draw with curve fitting on the X and Y axis . But what I want is to create mesh parts. Thank you very much in advance for your help in this matter.

Best regards.

close all
clear
clc

xk1=1:1:7; xk2=xk1; xk3=xk1; xk4=xk1; xk5=xk1; xk6=xk1; xk7=xk1;

x1=-15:0.4286:15; x2=x1; x3=x1; x4=x1; x5=x1; x6=x1; x7=x1;

y1=(-15.*ones(1,70));
y2=(-10.*ones(1,70));
y3=(-5.*ones(1,70));
y4=(0.*ones(1,70));
y5=(5.*ones(1,70));
y6=(10.*ones(1,70));
y7=(15.*ones(1,70));

%% Power Measurement
%%
zk1 = [85 85 85 85 85 85 85]; %-15
zk2 = [85 88 88 88 88 88 85]; %-10
zk3 = [85 88 95 95 95 88 85]; %-5
zk4 = [85 88 95 100 95 88 85]; %0
zk5 = [85 88 95 95 95 88 85]; %y5
zk6 = [85 88 88 88 88 88 85]; %y10
zk7 = [85 85 85 85 85 85 85]; %y15

dk1 = linspace(min(xk1), max(xk1), 70);
z1 = interp1(xk1, zk1, dk1, âpchipâ, âextrapâ);
dk2 = linspace(min(xk2), max(xk2), 70);
z2 = interp1(xk2, zk2, dk2, âpchipâ, âextrapâ);
dk3 = linspace(min(xk3), max(xk3), 70);
z3 = interp1(xk3, zk3, dk3, âpchipâ, âextrapâ);
dk4 = linspace(min(xk4), max(xk4), 70);
z4 = interp1(xk4, zk4, dk4, âpchipâ, âextrapâ);
dk5 = linspace(min(xk5), max(xk5), 70);
z5 = interp1(xk5, zk5, dk5, âpchipâ, âextrapâ);
dk6 = linspace(min(xk6), max(xk6), 70);
z6 = interp1(xk6, zk6, dk6, âpchipâ, âextrapâ);
dk7 = linspace(min(xk7), max(xk7), 70);
z7 = interp1(xk7, zk7, dk7, âpchipâ, âextrapâ);

%Power Values
xtp=[ x1; x2; x3; x4; x5; x6; x7 ];
ytp=[ y1; y2; y3; y4; y5; y6; y7 ];

%% Figure 1 Power
figure(1)
ztp1=[ z1; z2; z3; z4; z5; z6; z7 ];
surf (xtp,ytp,ztp1);

hold on;
grid on;
%% Figure 1 Visual Setting

colormap(âwhiteâ) % change color map
%shading interp % interpolate colors across lines and faces
box on; %frame line

ax = gca; % grid line thickness
ax.LineWidth = 1; % grid line thickness

fontname(gcf,âTimes New Romanâ); %all graph fontname

ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;
ax.ZAxis.FontSize = 12;

ax.XLim = [-15 15]; %x or y axis limit
ax.XTick = (-15:5:15); %x or y axis divided

ax.YLim = [-15 15]; %x or y axis limit
ax.YTick = (-15:5:15); %x or y axis divided

ax.ZLim = [80 100]; %x or y axis limit
ax.ZTick = (80:5:100); %x or y axis divided

xh = get(gca,âXLabelâ); % Handle of the y label
posx = get(xh, âPositionâ);
xlabel(â\it\Deltaxâ,âFontSizeâ,12, âPositionâ,posx.[0,1.1,1], âRotationâ,11);
yh = get(gca,âYLabelâ); % Handle of the y label
pos = get(yh, âPositionâ);
ylabel(â\it\Deltayâ,âFontSizeâ,12, âPositionâ,pos.
[0.99,-1.2,1], âRotationâ,-38);
zlabel(âOutput power, {\itP_{out}} (kW)â,âFontSizeâ,12);

set(gcf, âPositionâ, [900, 800, 400, 300]) % frame size
view(-30,35); %frame angle -20,25