Effacer les filtres
Effacer les filtres

Convert Radian to Degree in Plot axis only

20 vues (au cours des 30 derniers jours)
james hayek
james hayek le 11 Sep 2016
Commenté : ahmed samir le 20 Déc 2020
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')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Réponse acceptée

Star Strider
Star Strider le 11 Sep 2016
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 commentaires
Star Strider
Star Strider le 11 Sep 2016
My pleasure!
ahmed samir
ahmed samir le 20 Déc 2020
thanks

Connectez-vous pour commenter.

Plus de réponses (1)

Hasitha Madushan
Hasitha Madushan le 1 Avr 2020
How to convert Y-axis value to radiant value

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by