savePath = fullfile(pwd,"export.xml");
if exist("Maschinendaten")
tq_axis_pos = Maschinendaten.Kennfeld.M_max_mesh(:,1);
pwrMotLoss_pos = Maschinendaten.Kennfeld.Verluste.P_vges_mesh;
tq_axis = [-flip(tq_axis_pos); tq_axis_pos(2:end)];
pwrMotLoss = [flip(pwrMotLoss_pos); pwrMotLoss_pos(2:end,:)];
n_max = Maschinendaten.Optionen.n_max;
n_axis = Maschinendaten.Kennfeld.omega_k_mesh(1,1:end);
n_axis = n_max/max(n_axis)*n_axis;
tmp = "2,1|";
for i = 1:length(n_axis)
tmp = append(tmp, num2str(n_axis(i)));
if i ~= length(n_axis)
tmp = append(tmp,",");
else
tmp = append(tmp,";");
end
end
for i = 1:length(tq_axis)
tmp = append(tmp, num2str(tq_axis(i)));
if i ~= length(tq_axis)
tmp = append(tmp,",");
else
tmp = append(tmp,"|");
end
end
for j = 1:length(n_axis)
if isnan(pwrMotLoss(1,j))
idx1 = find(~isnan(pwrMotLoss(:,j)),1,'first');
pwrMotLoss(1:idx1-1,j) = pwrMotLoss(idx1,j);
end
if isnan(pwrMotLoss(end,j))
idx2 = find(~isnan(pwrMotLoss(:,j)),1,'last');
pwrMotLoss(idx2+1:end,j) = pwrMotLoss(idx2,j);
end
end
for i = 1:length(tq_axis)
for j = 1:length(n_axis)
if ~isnan(pwrMotLoss(i,j))
tmp = append(tmp,num2str(round(pwrMotLoss(i,j),2)));
if ~(i == length(tq_axis) && j == length(n_axis))
tmp = append(tmp,",");
end
end
end
end
docNode = com.mathworks.xml.XMLUtils.createDocument('routes');
routes = docNode.getDocumentElement;
vType = docNode.createElement('vType');
routes.appendChild(vType);
param = docNode.createElement('param');
param.setAttribute('key','powerLossMap');
param.setAttribute('value',tmp);
vType.appendChild(param);
xmlwrite(savePath,docNode);
winopen(savePath);
else
disp('Maschinendaten missing. Please load them into the workspace.');
end