Creating vector of real numbers and use it in another function

1 view (last 30 days)
Hi,
I would like to create a vector with 1 row that contains real numbers from 10 to 90. I would also like to use this array of numbers within a for loop which takes in each of those numbers for processing. Here is the messy version I have.
*Rather than writing these numbers out in a primitive fashion, I would like to create a loop here to generate real numbers between 10 and 90*.
inc =[10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90]
n1 = 1
e_r = 2.3
mu_r = 1
mu_0 = 4e-7*pi
e_0 = 8.8541878176e-12
n2 = sqrt(mu_r*e_r)
imp_0 = 120*pi
imp_r = sqrt((mu_0*mu_r)/(e_0*e_r))
I would like to use the array of vectors here for each real number between 10 and 90. My loop goes from 1 to 81 because there are 81 values between 10 and 90(including 10 and 90.)
for index = 1:81
tran(index)= asind(((n1*sind(inc(index)))/n2));
ref_coeff_para(index) = abs((imp_0*cosd(inc(index))-imp_r*cosd(tran(index)))/(imp_r*cosd(tran(index))+imp_0*cosd(inc(index))))
trans_coeff_para(index) = abs(2*imp_r*cosd(inc(index))/(imp_r*cosd(tran(index))+imp_0*cosd(inc(index))))
ref_coeff_perp(index) = abs((imp_r*cosd(inc(index))-imp_0*cosd(tran(index)))/(imp_r*cosd(inc(index))+imp_0*cosd(tran(index))))
trans_coeff_perp(index) = abs(2*imp_r*cosd(inc(index))/(imp_r*cosd(inc(index))+imp_0*cosd(tran(index))))
end
Any help is appreciated

Accepted Answer

Stephen23
Stephen23 on 7 Sep 2016
Edited: Stephen23 on 7 Sep 2016
Instead of laboriously writing out every number, why not get the computer to create that vector using the colon operator:
inc = 10:90;
and then simply write your loop to iterate over all of its elements:
for index = 1:numel(inc)
...
end
You might like to do the introductory tutorials, which introduce these kinds of basic MATLAB usage:

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!