我想在同一個圖上繪製電動機的功率和轉矩。 我用一個循環來繪製三角形星形配置,還有一個雙齒輪系統,所以我會爲每個配置繪製2個系列數據(功率和扭矩)。 我試過這個,但我注意到,在第二個循環中繪製在第二個軸,而不是在第一個。我使用MATLAB 2015年,所以我沒有yyaxis function
Matlab - 如何繪製不同的y軸
clc; clear all;close all
tau=[8.823;1.604]; %in ordine decrescente
n_gamme=length(tau);
data=[22 22;575 1200;1500 6000;365 175];%P,Ginocchio,rpm max,C
names={'Star';'Delta'};
nN=zeros(2);nmax=zeros(2);M_N=zeros(2); %inizializzo
for i=1:n_gamme %contatore gamme
% j=1; se non ho stella-triangolo
for j=1:2 %contatore stella-triangolo
P=data(1); %potenza max
nN(i,j)=data(2,j)./tau(i); %rpm, ginocchio
nmax(i,j)=data(3,j)/tau(i); %giri max
M_N(i,j)=data(4,j)*tau(i); %coppia max
end
end
PL=['r','r-';'g','g-'];
% j=1; %se non ho stella-triangolo
for j=1:2 %contatore stella-triangolo
% subplot(length(tau),1,j);
% figure
x1(j,:) = linspace(0,nN(1,j)); %numero di giri da 0 al ginocchio 1
x2(j,:) = linspace(nN(1,j),nmax(1,j)); %da ginocchio 1 a max 1
x3(j,:) = linspace(0,nN(2,j)); %da 0 a ginocchio 2
x4(j,:) = linspace(nN(2,j),nmax(2,j)); %da ginocchio 2 a max 2
C_1(1,j)=M_N(1,j); %coppia costante 1 marcia
C_2(j,:)=30*P*1000./(pi*x2(j,:)); %coppia 1 marcia
C_3(2,j)=M_N(2,j); %coppia costante 2 marcia
C_4(j,:)=30*P*1000./(pi*x4(j,:)); %coppia 2 marcia
ax1 = gca;
plot(ax1,[0,nN(1,j)],[C_1(1,j) C_1(1,j)],PL(1,j),'LineWidth',2/j^2) %I coppia costante
hold on
plot(ax1,x2(j,:),C_2(j,:),PL(2,j),'LineWidth',2/j^2) %coppia I
plot(ax1,[max(x2(j,:)),nN(2,j)],[C_3(2,j) C_3(2,j)],PL(1,j),'LineWidth',2/j^2) %II coppia costante
plot(ax1,x4(j,:),C_4(j,:),PL(2,j),'LineWidth',2/j^2) %coppia II
ylim([0 3500])
ylabel(ax1,'Torque [Nm]'); %# Add a label to the left y axis
set(ax1,'Box','off');%# Turn off the box surrounding the whole axes
axesPosition = get(gca,'Position');
ax2 = axes('Position',axesPosition,...
'YLim',[0 30],... %# and a different scale
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','b','YColor','b',...
'Box','off'); %# ... and no surrounding box
hold on
m=P./nN; %pendenza potenza
P_1(j,:)=m(1,j).*x1(j,:); %potenza 1 marcia
P_2(1,j)=P; %Potenza costante 1 marcia
P_3(j,:)=m(2,j).*x3(j,:); %Potenza 2 marcia
P_4(2,j)=P; %Potenza costante 2 marcia
plot(ax2,x1(j,:),P_1(j,:),'b--')
plot(ax2,[max(x1(j,:)),nmax(1,j)],[P P],'b--')
plot(ax2,x3(j,:),P_3(j,:),'b--')
plot(ax2,[max(x3(j,:)),nmax(2,j)],[P P],'b--')
ylabel(ax2,'Power [kW]');
linkaxes([ax1 ax2],'x'); %lega tra di loro gli assi,
grid on
grid minor
end
我怎麼能在同一尺度繪製
沒錯。我解決了,謝謝 – Andrea