- "doesn't for some reason"   how do you know it does not?
- Do you know how to use breakpoints?
How to get my code to define variables
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi, I've written a quick piece of code which is the following:
function [Delta, theta, theta1, theta1prim, theta2prim, theta2] = mindeviation(n, A)
n0 = 1;
Delta = asin(n/n0 * sin(A/2))*2 - A;
theta = (Delta + A)/2;
disp(['Minimum deviation is ' num2str(Delta) ' radians or ' num2str(Delta*180/pi) ' degrees.'])
disp(['The angle of incidence is ' num2str(theta) ' radians or ' num2str(theta*180/pi) ' degrees.'])
theta1 = linspace(0,pi/2);
theta1prim = (asin(sin(theta1)/n));
theta2prim = (A-theta1prim);
theta2 = (asin(n*sin(theta2prim)));
Delta2 = theta1 + theta2 - theta1prim - theta2prim;
plot(theta1*180/pi,Delta2*180/pi)
xlabel('Angle of incidence (deg)')
ylabel('Angle of deviation (deg)')
xlim([0 90])
ylim([10 45])
I want it to define Delta, theta, and so on in Matlab when I run it but it doesn't for some reason so I figured I must be missing something important, but I can't find it whatever I try. Can anyone help me how to fix it? Thanks a lot for your time.
댓글 수: 1
per isakson
2015년 3월 28일
편집: per isakson
2015년 3월 28일
답변 (2개)
James Tursa
2015년 3월 28일
편집: James Tursa
2015년 3월 28일
I assume you mean you want to capture the variables Delta, theta, etc in the workspace where mindeviation is called. You must do so explicitly. E.g.,
n = whatever
A = whatever
[Delta, theta, theta1, theta1prim, theta2prim, theta2] = mindeviation(n, A);
Now you should have Delta, theta, etc in your workspace.
댓글 수: 0
Star Strider
2015년 3월 28일
You didn’t post any of your other code, so I can only guess you are not actually calling your function. In your main script, include this line:
[Delta, theta, theta1, theta1prim, theta2prim, theta2] = mindeviation(n, A);
You should have all the returned values in your MATLAB main script workspace. Your function doesn’t know you want it to run unless you tell it to.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!