MATLAB Answers

Creating a mesh in a 3-d plot.

1 view (last 30 days)
ragnor
ragnor on 17 Aug 2021
Commented: ragnor on 17 Aug 2021
Hello matlab community,
Can someone please help me to create a mesh surface where the points are connected and it looks like the picture attached. I have the following code which just connects the points with the line but the surface is not seen. I am not able to figure the meshgrid and how to apply it to fit my requirement. I would be really grateful if somone can help.
opts = detectImportOptions('Data1.xlsx');
opts1 = detectImportOptions('Data2.xlsx');
% Load data
data = readtable('Data1.xlsx', opts);
data1 = readtable('Data2.xlsx', opts1);
x1 = data{:,1};
y1 = data{:,2};
z1 = data{:,3};
x2 = data1{:,1};
y2 = data1{:,2};
z2 = data1{:,3};
figure(1)
plot3(y1,x1,z1, 'x-o','LineWidth',1);
hold on;
plot3(y2,x2,z2, 'x-o','LineWidth',1);
hold off;
legend('$25^{\circ}C$','$150^{\circ}C$',...
'Location','northoutside','Orientation','horizontal')

Accepted Answer

Yazan
Yazan on 17 Aug 2021
Edited: Yazan on 17 Aug 2021
clc, clear, close all
opts = detectImportOptions('Data1.xlsx');
opts1 = detectImportOptions('Data2.xlsx');
% Load data
data = readtable('Data1.xlsx', opts);
data1 = readtable('Data2.xlsx', opts1);
x1 = data{:,1};
y1 = data{:,2};
z1 = data{:,3};
x2 = data1{:,1};
y2 = data1{:,2};
z2 = data1{:,3};
xx1 = reshape(x1(:), [], length(unique(x1)));
yy1 = reshape(y1(:), length(unique(y1)), []);
zz1 = reshape(z1(:), size(xx1));
surf(yy1, xx1, zz1, 'FaceColor', 'b', 'FaceAlpha', 0.1, 'EdgeColor', 'b', 'Marker', ...
's', 'MarkerSize', 7, 'MarkerFaceColor', 'b');
hold on
xx2 = reshape(x2(:), [], length(unique(x2)));
yy2 = reshape(y2(:), length(unique(y2)), []);
zz2 = reshape(z2(:), size(xx2));
surf(yy2, xx2, zz2, 'FaceColor', 'r', 'FaceAlpha', 0.1, 'EdgeColor', 'r', 'Marker',...
's', 'MarkerSize', 7, 'MarkerFaceColor', 'r');
xlabel('I_{on} [A]'), ylabel('V_{block} [V]'), zlabel('E [mJ]')
legend(' 25^o', ' 150^o')
  1 Comment
ragnor
ragnor on 17 Aug 2021
@Yazan: Thank you so much, i have no words to express my gratitude :)

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by