Filter löschen
Filter löschen

Convert Radian to Degree in Plot axis only

20 Ansichten (letzte 30 Tage)
james hayek
james hayek am 11 Sep. 2016
Kommentiert: ahmed samir am 20 Dez. 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')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
Star Strider
Star Strider am 11 Sep. 2016
My pleasure!
ahmed samir
ahmed samir am 20 Dez. 2020
thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Hasitha Madushan
Hasitha Madushan am 1 Apr. 2020
How to convert Y-axis value to radiant value

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by