Convert Radian to Degree in Plot axis only
22 次查看(过去 30 天)
显示 更早的评论
I would like to show the X axis as degrees in the plot. The code has used radians all throughout.
Is there a way to convert the X axis values to represent degrees as oposed to radians?
My code is as follows:
% James
%
% Setting up the variables for the parameters
n1 = 1;
n2 = 1.5;
% We are looking to range theata_i from 0 t 90 degrees
% Using the linspace() command we can range values over some interval using
% the last argument as a step or incriment value
theata_i = linspace(0,pi/2,50)
% The value of theata_t as per Snells Law
theata_t = asin((n1/n2)*(sin(theata_i)))
% Notice the use of ./ this is an element by element divide, if we were to
% just use the divide sign, / , we would be dividing a scalar and would not
% get the array of values we are interested in.
reflectedPerpendic = (n1*cos(theata_i) - n2*cos(theata_t))./(n1*cos(theata_i) + n2*cos(theata_t))
% Using the plot function
plot( abs(theata_t), abs(reflectedPerpendic),'--r*')
%title('Graph of Reflected Perpencular Component')
hold
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Same approach for the transmitted Perpendic value
transmittedPerpendic = (2*n1*cos(theata_i))./(n1*cos(theata_i) + n2*cos(theata_t))
% Ploting the above
plot( abs(theata_t), abs(transmittedPerpendic),'--b*')
title('Graph of Reflected & Transmitted Perpencular Components')
xlabel('0 < theata_i < pi/2')
ylabel('Reflected = Red, Transmitted = Blue')
figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Same approach for the reflected Paralell value
reflectedParalell = (n2*cos(theata_i) - n1*cos(theata_t))./(n2*cos(theata_i) + n1*cos(theata_t))
% Ploting the above
plot( abs(theata_t), abs(reflectedParalell),'--g*')
%title('Graph of Reflected Paralell Component')
hold
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Same approach for the transmitted Paralell value
transmittedParalell = (2*n1*cos(theata_i))./(n1*cos(theata_t) + n2*cos(theata_i))
% Ploting the above
plot( abs(theata_t), abs(transmittedParalell),'--m*')
title('Graph of Reflected & Transmitted Paralell Components')
xlabel('0 < theata_i < pi/2')
ylabel('Reflected = Green, Transmitted = Magenta')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0 个评论
采纳的回答
Star Strider
2016-9-11
Try this:
% James
%
% Setting up the variables for the parameters
n1 = 1;
n2 = 1.5;
% We are looking to range theata_i from 0 t 90 degrees
% Using the linspace() command we can range values over some interval using
% the last argument as a step or incriment value
theata_i = linspace(0,pi/2,50);
% The value of theata_t as per Snells Law
theata_t = asin((n1/n2)*(sin(theata_i)));
% Notice the use of ./ this is an element by element divide, if we were to
% just use the divide sign, / , we would be dividing a scalar and would not
% get the array of values we are interested in.
reflectedPerpendic = (n1*cos(theata_i) - n2*cos(theata_t))./(n1*cos(theata_i) + n2*cos(theata_t));
% Using the plot function
plot( abs(theata_t), abs(reflectedPerpendic),'--r*')
%title('Graph of Reflected Perpencular Component')
hold
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Same approach for the transmitted Perpendic value
transmittedPerpendic = (2*n1*cos(theata_i))./(n1*cos(theata_i) + n2*cos(theata_t));
% Ploting the above
plot( abs(theata_t), abs(transmittedPerpendic),'--b*')
title('Graph of Reflected & Transmitted Perpencular Components')
% xlabel('0 < theata_i < pi/2')
ylabel('Reflected = Red, Transmitted = Blue')
xtixr = get(gca, 'XTick');
xtixlbl = regexp(sprintf('%.1f°\n',xtixr*180/pi), '\n', 'split');
set(gca, 'XTick', xtixr, 'XTickLabel',xtixlbl)
xlabel('0 < theta_i < 180°')
figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Same approach for the reflected Paralell value
reflectedParalell = (n2*cos(theata_i) - n1*cos(theata_t))./(n2*cos(theata_i) + n1*cos(theata_t));
% Ploting the above
plot( abs(theata_t), abs(reflectedParalell),'--g*')
%title('Graph of Reflected Paralell Component')
hold
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Same approach for the transmitted Paralell value
transmittedParalell = (2*n1*cos(theata_i))./(n1*cos(theata_t) + n2*cos(theata_i));
% Ploting the above
plot( abs(theata_t), abs(transmittedParalell),'--m*')
title('Graph of Reflected & Transmitted Paralell Components')
% xlabel('0 < theata_i < pi/2')
xtixr = get(gca, 'XTick');
xtixlbl = regexp(sprintf('%.1f°\n',xtixr*180/pi), '\n', 'split');
set(gca, 'XTick', xtixr, 'XTickLabel',xtixlbl);
xlabel('0 < theta_i < 180°')
ylabel('Reflected = Green, Transmitted = Magenta')
3 个评论
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!