Problem with Plot 3D
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello Matlab Community,
I am trying to plot a 3D coloured with some data, however the plot is looking a bit different. The negative and positive values in the Z matrix are identical only difference is the sign. But the plot doesnt look identical in the negative and positive axis. It would be great if someone could help me with this.
data = readtable('Data1.xlsx');
x = data(:,1:3);
x = table2array(x);
t = data(:,4);
t = table2array(t);
X = x(:,1);
Y = x(:,3);
Z = t;
N = 200 ;
x = linspace(min(X),max(X),N) ;
y = linspace(min(Y),max(Y),N) ;
[Xi,Yi] = meshgrid(x,y) ;
Zi = griddata(X,Y,Z,Xi,Yi) ;
surf(Xi,Yi,Zi)
댓글 수: 2
Rik
2021년 7월 23일
Why did you delete the excel file? If you don't want public help, you should have hired a private consultant.
Why should the figure (or the axis labels) be removed? Without the rest of the paper, this doesn't say much.
채택된 답변
Cris LaPierre
2021년 7월 19일
편집: Cris LaPierre
2021년 7월 19일
It looks like, in your Excel sheet, you have erroneously recorded all Y values of -7 as 7. That could explain part of the issue.
Once that is done, you might quickly view the results with the following code.
% Load data
data = readtable('Data1.xlsx','VariableNamingRule',"preserve");
data.Properties.VariableNames = ["X","F_sw","Y","Z"];
% order the data
data = sortrows(data,["X","Y"]);
X = unique(data.X);
Y = unique(data.Y);
Z = reshape(data.Z,[length(Y),length(X)]);
% View
figure
surf(X,Y,Z)
댓글 수: 3
Cris LaPierre
2021년 7월 20일
Legend items correspond to plot objects. If you want two items in your legend, you need two distinct objects in your axes. You currently have one, a surface. Create your surface using surf, and add a second object for your markers, perhaps using scatter, and then you can create a legend with 2 items in it.
% Load data
data = readtable('Data1.xlsx');
data.Properties.VariableNames = ["X","F_sw","Y","Z"];
% order the data
data = sortrows(data,["X","Y"]);
X = unique(data.X);
Y = unique(data.Y);
Z = reshape(data.Z,[length(Y),length(X)]);
% View
figure(1)
scatter3(data.X,data.Y,data.Z,12,[1 0 0],"filled","MarkerEdgeColor",[0 0 0])
hold on
s = surf(X,Y,Z,"FaceColor",[0.784 0.816 0.831]);
hold off
xlabel('DC-Link Voltage (V)',"FontSize",10,"FontWeight","normal");
ylabel('Phase Current (A)',"FontSize",10,"FontWeight","normal");
zlabel('Error Voltage (V)',"FontSize",10,"FontWeight","normal");
title('title','FontSize',10,'fontweight', 'normal');
legend("Label 1","Label 2")
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!