-
Notifications
You must be signed in to change notification settings - Fork 3
/
plotData.m
210 lines (184 loc) · 6.8 KB
/
plotData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
function plotData(condition,conditionLabels,voltData,...
xData,yData,zData,xIndex,yIndex,zIndex,xScale,yScale,zScale,Jconv)
% CONDITION cell of array of propeller data. Each condition is an array of double
% CONDITIONLABELS cell array of strings indicating each condition name
% VOLTDATA voltage data as loaded in the main file
% XDATA x array as generated by meshgrid
% YDATA y array as generated by meshgrid
% ZDATA z array as generated by griddata
% XINDEX index of the x-axis as in the main file and the following table
% YINDEX index of the y-axis as in the main file and the following table
% ZINDEX index of the z-axis as in the main file and the following table
% XSCALE scale factor of the x-axis
% XSCALE scale factor of the y-axis
% XSCALE scale factor of the z-axis
% JCONV conversion factor from RPM to J (advance ratio)
%
% Possible values of XINDEX, YINDEX, ZINDEX
%
% 1 Current
% 2 Input (electric) power
% 3 RPM
% 4 Torque
% 5 Output (shaft) power
% 6 Motor efficiency
%
% For values outside the above range this function throws an error.
% Assign correct label to plot
indexArray = [xIndex, yIndex, zIndex];
labelArray = {};
for i = 1:3 % x, y, z
switch indexArray(i)
case 1
labelArray{i} = 'Current, A';
contourLevels = 20;
case 2
labelArray{i} = 'Input (electric) power, W';
contourLevels = 20;
case 3
labelArray{i} = 'RPM';
contourLevels = 20;
case 4
labelArray{i} = 'Torque, Ncm';
contourLevels = 20;
case 5
labelArray{i} = 'Output (shaft) power, W';
contourLevels = 0:50:700;
case 6
labelArray{i} = 'Motor efficiency';
contourLevels = [5:10:85,85:2:90,90:0.5:95];
otherwise
error('Data indices must br between 1 and 6');
end
end
figure
hold on
surf(xData,yData,zData,'FaceColor','interp','LineStyle','none')
voltagePlot3(voltData,xIndex,yIndex,zIndex,xScale,yScale,zScale)
% Add propeller operating conditions
for i = 1:numel(condition)
% create a temporary variable to access part of cell data
tempMat = condition{i};
% reorder the temporary array to match XINDEX, YINDEX, ZINDEX
% CONDITION = [J, SHAFT POWER, RPM, CURRENT, TORQUE, EFFICIENCY];
tempMat = tempMat(:,[4,5,3,5,2,6]);
tempMat(:,2) = NaN; % electric power not defined for propeller data
% show only makers if there is only 1 data point per condition
if size(tempMat,1) == 1
conditionCurves{i} = ...
scatter3(tempMat(:,xIndex),tempMat(:,yIndex),tempMat(:,zIndex)*1.01,...
'filled','MarkerEdgeColor','black');
else
conditionCurves{i} = ...
plot3(tempMat(:,xIndex),tempMat(:,yIndex),tempMat(:,zIndex)*1.01,...
'-o','LineWidth',3.0,'MarkerSize',3,'MarkerEdgeColor','black');
end
end
hold off, grid on, view(-20,30)
xlabel(labelArray{1}), ylabel(labelArray{2}), zlabel(labelArray{3})
colorbar
legend([conditionCurves{:}],conditionLabels,'Location','Best')
% Annotations on surf
annot3(voltData,xIndex,yIndex,zIndex,xScale,yScale,zScale)
for i = 1:numel(condition)
tempMat = condition{i};
tempMat = tempMat(:,[4,5,3,5,2,6]);
tempMat(:,2) = NaN; % electric power not defined for propeller data
for j = 1:size(tempMat,1)
text(tempMat(j,xIndex),tempMat(j,yIndex),tempMat(j,zIndex)*1.01,...
['T = ',num2str(condition{i}(j,1),'%.1f'), ' N \rightarrow'], ...
'HorizontalAlignment','right')
end
end
% Eventually scale the thick labels
tempLabel = xticklabels;
for i = 1:numel(tempLabel)
tempLabel{i} = str2double(tempLabel{i}) * xScale;
tempLabel{i} = num2str(tempLabel{i});
end
xticklabels(tempLabel)
tempLabel = yticklabels;
for i = 1:numel(tempLabel)
tempLabel{i} = str2double(tempLabel{i}) * yScale;
tempLabel{i} = num2str(tempLabel{i});
end
yticklabels(tempLabel)
tempLabel = zticklabels;
for i = 1:numel(tempLabel)
tempLabel{i} = str2double(tempLabel{i}) * zScale;
tempLabel{i} = num2str(tempLabel{i});
end
zticklabels(tempLabel)
% Contour plot
figure
hold on
[C,H] = contourf(xData,yData,zData,contourLevels);
voltagePlot(voltData,xIndex,yIndex,xScale,yScale)
for i = 1:numel(condition)
% create a temporary variable to access part of cell data
tempMat = condition{i};
% reorder the temporary array to match XINDEX, YINDEX, ZINDEX
% CONDITION = [J, SHAFT POWER, RPM, CURRENT, TORQUE, EFFICIENCY];
tempMat = tempMat(:,[4,5,3,5,2,6]);
tempMat(:,2) = NaN; % electric power not defined for propeller data
% show only makers if there is only 1 data point per condition
if size(tempMat,1) == 1
conditionCurves{i} = ...
scatter(tempMat(:,xIndex),tempMat(:,yIndex),...
'filled','MarkerEdgeColor','black');
else
conditionCurves{i} = ...
plot(tempMat(:,xIndex),tempMat(:,yIndex),...
'-o','LineWidth',3.0,'MarkerSize',3,'MarkerEdgeColor','black');
end
end
hold off
clabel(C,H,'FontSize',15)
xlabel(labelArray{1}), ylabel(labelArray{2}), title(labelArray{3})
% colorbar
legend([conditionCurves{:}],conditionLabels,'Location','Best')
% Set two lines for the axis showing RPM and J
if xIndex == 3 % RPM
xticks(0:11);
xticklabels([]);
xlabel([])
xx = xticks;
xl = xlim;
newTickScale = xx(end)/xl(end) / (length(xx)-1);
for i = 1:length(xx)
text((i-1)*newTickScale,-0.03,num2str(xx(i)*xScale,'%.0f'),...
'Units','normalized','HorizontalAlignment','center')
text((i-1)*newTickScale,-0.08,num2str(Jconv/(xx(i)*xScale),'%.2f'),...
'Units','normalized','HorizontalAlignment','center')
end
text(-0.03,-0.03,'RPM','Units','normalized','HorizontalAlignment','right')
text(-0.03,-0.08,'J','Units','normalized','HorizontalAlignment','right')
else
% Scale the X thick labels
tempLabel = xticklabels;
for i = 1:numel(tempLabel)
tempLabel{i} = str2double(tempLabel{i}) * xScale;
tempLabel{i} = num2str(tempLabel{i});
end
xticklabels(tempLabel)
end
% Scale the Y thick labels
tempLabel = yticklabels;
for i = 1:numel(tempLabel)
tempLabel{i} = str2double(tempLabel{i}) * yScale;
tempLabel{i} = num2str(tempLabel{i});
end
yticklabels(tempLabel)
% Annotations on contour
annot(voltData,xIndex,yIndex,xScale,yScale)
for i = 1:numel(condition)
tempMat = condition{i};
tempMat = tempMat(:,[4,5,3,5,2,6]);
tempMat(:,2) = NaN; % electric power not defined for propeller data
for j = 1:size(tempMat,1)
text(tempMat(j,xIndex),tempMat(j,yIndex),...
['T = ',num2str(condition{i}(j,1),'%.1f'), ' N \rightarrow'], ...
'HorizontalAlignment','right')
end
end
end