How to plot the surface of multiple data sets ?

I have three different data sets each being constant in the z/l axis and want to plot the surface of them. I got the 3d plot working using plot3() :
All three lines have the same amount of data points so it should not be that hard to connect each point of each line with a straight line.
Here's the code for the figure:
figure(35);
set(gcf,'position',[x0,y0,width,height])
plot3(porous_upper(pathnumber_10,1).values(:,xc_x)*scale_x,porous_upper(pathnumber_10,1).values(:,xc_x+2)*scale_z,porous_upper(pathnumber_10,1).values(:,yc_x),"DisplayName","Porous Upper 1 p -10");
hold on;
plot3(porous_upper(pathnumber_10,2).values(:,xc_x)*scale_x,porous_upper(pathnumber_10,2).values(:,xc_x+2)*scale_z,porous_upper(pathnumber_10,2).values(:,yc_x),"DisplayName","Porous Upper 2 p -10");
hold on;
plot3(porous_upper(pathnumber_10,3).values(:,xc_x)*scale_x,porous_upper(pathnumber_10,3).values(:,xc_x+2)*scale_z,porous_upper(pathnumber_10,3).values(:,yc_x),"DisplayName","Porous Upper 3 p -10");
title(["Pressure p above porous layer";"Sidecoefficent Test -10"],'interpreter','latex',"FontSize",20)
set(gca, 'YDir','reverse')
xlabel('X/L', 'Interpreter','latex',"FontSize",16);
ylabel('Z/L', 'Interpreter','latex',"FontSize",20);
zlabel('$p$', 'Interpreter','latex',"FontSize",20);
legend("show","Location","Best","AutoUpdate", "off");

 Akzeptierte Antwort

It would help to have the actual data.
N = 20;
X = (0:N-1);
Y = [1:3].'+zeros(size(X));
porous_upper = rand(20,3)+[0:2];
figure
plot3(X, Y(1,:), porous_upper(:,1))
hold on
plot3(X, Y(2,:), porous_upper(:,2))
plot3(X, Y(3,:), porous_upper(:,3))
hold off
grid on
figure
surf(porous_upper.')
Make appropriate changes to work with your data.
.

6 Kommentare

Jean Volkmar
Jean Volkmar am 20 Aug. 2021
Bearbeitet: Jean Volkmar am 20 Aug. 2021
Thank you for the answer, i attached the data. Coloumn 4 represents the z axis while column 7 the x axis and column 9 the y axis when using plot3(x,y,z).
porous_upper is a n x 3 struct where porous_upper(n,1) reffers to the data file if Porous_Upper_1 and so on. With only 3 data files n will be 1.
Edit:
As i understood your example uses the row and colomun numbers from porous_upper as x and y coordinate and the z coordinate is saves into the corresponding cell. However this wont work for me since my data points are not integers with a spacing of exactly 1 to each other.
My pleasure!
I am not certain what result you want.
One option (essentially my previous code with your data) —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/717019/Porous_Upper_1.csv', 'VariableNamingRule','preserve');
T2 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/717009/Porous_Upper_2.csv', 'VariableNamingRule','preserve');
T3 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/717014/Porous_Upper_3.csv', 'VariableNamingRule','preserve');
% Q1 = [size(T1); size(T2); size(T3)]
Q1 = 3×2
1001 9 1001 9 1001 9
X = [T1{:,7} T2{:,7} T3{:,7}];
Y = [T1{:,9} T2{:,9} T3{:,9}];
Z = [T1{:,4} T2{:,4} T3{:,4}];
figure
hold on
for k = 1:size(Z,2)
plot3(X(:,k), Y(:,k), Z(:,k))
end
hold off
grid on
view(150,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
legend(compose('Upper Porous %d', 1:3), 'Location','bestoutside')
figure
meshc(X, Y, Z)
% surfc(X, Y, Z, 'EdgeColor','none')
grid on
view(150,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
Make appropriate changes to get the result you want.
.
Many thanks ! That:
X = [T1{:,7} T2{:,7} T3{:,7}];
Y = [T1{:,9} T2{:,9} T3{:,9}];
Z = [T1{:,4} T2{:,4} T3{:,4}
was the information i was missing. Is there also a way to control the mesh density, like here ?
My pleasure!
Reducing the mesh density requires reducing the plotted data, since the data define the surface. I am not certain what result you want. One option is to use surf (or surfc instead, my initial choice), and ‘turn off’ the edge lines:
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/717019/Porous_Upper_1.csv', 'VariableNamingRule','preserve');
T2 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/717009/Porous_Upper_2.csv', 'VariableNamingRule','preserve');
T3 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/717014/Porous_Upper_3.csv', 'VariableNamingRule','preserve');
% Q1 = [size(T1); size(T2); size(T3)]
X = [T1{:,7} T2{:,7} T3{:,7}];
Y = [T1{:,9} T2{:,9} T3{:,9}];
Z = [T1{:,4} T2{:,4} T3{:,4}];
figure
surfc(X, Y, Z, 'EdgeColor','none')
grid on
view(150,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
or alternatively using the shading function:
figure
surfc(X, Y, Z)
grid on
view(150,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
shading('interp') % Added
Rotate it using the view function to the orientation you want.
.
Alright thanks alot ! :)
As always, my pleasure!
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by