필터 지우기
필터 지우기

Convert Radian to Degree in Plot axis only

조회 수: 28 (최근 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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by