Convert Radian to Degree in Plot axis only

22 ビュー (過去 30 日間)
james hayek
james hayek 2016 年 9 月 11 日
コメント済み: ahmed samir 2020 年 12 月 20 日
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')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

採用された回答

Star Strider
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 件のコメント
Star Strider
Star Strider 2016 年 9 月 11 日
My pleasure!
ahmed samir
ahmed samir 2020 年 12 月 20 日
thanks

サインインしてコメントする。

その他の回答 (1 件)

Hasitha Madushan
Hasitha Madushan 2020 年 4 月 1 日
How to convert Y-axis value to radiant value
  1 件のコメント
Hasitha Madushan
Hasitha Madushan 2020 年 4 月 2 日
plz answer me

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by