-1

Good morning, I am trying to plot this figure with the same code in Matlab. However it does not work at all. I simply can not get the same figure but instead using plotyy. The reason I need it with plotyy is make the reader understand the significance of the left hand numbers by plotting the same function but multiplied by a constant. The right hand side will be called the Gain and thus the reader will know at least how much gain is achieved for certain power. HEre is the code:

[![r=1:0.001:3;
R=50;
kappa=0.5;
L1=1000;
c1=R/(8*kappa*L1);
Frmin=(r+r.^-1).*(r-1)./(r+1);
Frmax=(r+r.^-1).*(atan(r)-atan(1./r));
P1min=c1.*Frmin;% the 1st function for the left hand side of plotyy
P1max=c1.*Frmax;% the 2nd function for the left hand side of plotyy
YYmin=P1min*20; % the 1st function for the right hand side of plotyy
YYmasx=P1max*20;% the 2nd function for the right hand side of plotyy
figure;
ha1 = area(\[1 3\], \[0 M.*c1\]);
hold on
plot(r,P1min,'r','Linewidth',8)
fill(\[r fliplr(r)\],\[P1min,fliplr(P1max)\],'y')
plot(r,P1max,'k','Linewidth',5);
hold off
legend('\Delta >0','\Delta=0', '\Delta<0','Pmax')
%,'900','800','700','600','500')
xlabel('r')
ylabel('P_p (W)')
title('P_p vs r for L= 1000 m')][1]][1]

So i hope I can get some help with this. I could show you some of my trials error attempts but then I would not be clear of my goal which is again to plot the same figure with same colors but using plotyy. Thank you and sorry for the long message.

  • Is the first line supposed to be `r = 1:0.001:3;`? And in `ha1 = area(\[1 3\], \[0 M.*c1\]);`, what do you mean? And what is M? Get your example working and I might be able to help you. – jkazan May 10 '16 at 06:20

1 Answers1

0

Is this what you're looking for?

Edit of your code (this is working):

r=1:0.001:3;
R=50;
kappa=0.5;
L1=1000;
c1=R/(8*kappa*L1);
Frmin=(r+r.^-1).*(r-1)./(r+1);
Frmax=(r+r.^-1).*(atan(r)-atan(1./r));
P1min=c1.*Frmin;% the 1st function for the left hand side of plotyy
P1max=c1.*Frmax;% the 2nd function for the left hand side of plotyy
YYmin=P1min*20; % the 1st function for the right hand side of plotyy
YYmasx=P1max*20;% the 2nd function for the right hand side of plotyy
figure;
M = 1;
ha1 = area([1 3], [0 M.*c1]);
hold on
plot(r,P1min,'r','Linewidth',8)
fill([r fliplr(r)],[P1min,fliplr(P1max)],'y')
plot(r,P1max,'k','Linewidth',5);

Your factor and plotyy

myFactor1 = 5;
[ax,~,~] = plotyy(r,P1min,r,myFactor1*P1min);

Set axes colors to black and control fonts

set(ax,{'ycolor'},{'k';'k'},{'FontSize'},{8;15})

rest of code, edited and now working

legend('\Delta >0','\Delta=0', '\Delta<0','Pmax')
xlabel('r')
ylabel('P_p (W)')
title('P_p vs r for L= 1000 m')
jkazan
  • 1,149
  • 12
  • 29
  • Thank you for the effort and help. I would like to display both y-axes in black color and control their fonts. I tried adding the function gca and i was able to change color and font however for some reason i lose the plot itself. Any comment on that? – Abed Libnan Haidar May 14 '16 at 21:55
  • The solution is added to the answer ;) I'd appreciate if you would accept the answer if it solves your initial problem. Thanks buddy! – jkazan May 15 '16 at 09:07