- "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
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
per isakson
am 28 Mär. 2015
Bearbeitet: per isakson
am 28 Mär. 2015
Antworten (2)
James Tursa
am 28 Mär. 2015
Bearbeitet: James Tursa
am 28 Mär. 2015
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 Kommentare
Star Strider
am 28 Mär. 2015
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 Kommentare
Siehe auch
Kategorien
Mehr zu Whos 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!