Iterate over two arrays
34 views (last 30 days)
Show older comments
Hi,
I would like to write a code whith two arrays as inputs: W_C and L_C
I want to calculate some formulas for each value. for instant:
W_C=[ 1 2 3 4]
L_C=[ 5 6 7 8]
I want to calculate all for mulas when:
W_C = 1 and L_C=[5 6 7 8]
W_C= 2 and L_C=[5 6 7 8]
.
.
W_C=4 and L_C=[5 6 7 8]
So, I should have 16 results. Here is a code I'm thinking of. however, I get following error:
Index in position 2 exceeds array bounds (must not exceed 1).
Thanks
Here is the code:
clc;
clear all;
close all;
W_C=[0.35 0.5 0.65 0.80];
L_C=[3 4.5 6 7.5];
H=0.035;
epsilon_r=3.38;
for i=1:length(W_C)
W_C=W_C(1,i);
epsilon_o=8.85418782*10^(-12);
epsilon_re=0.5*(epsilon_r+1)+0.5*(epsilon_r-1)*(1+12*(H./W_C)).^(-0.5);
C_I=0.5*epsilon_o*(epsilon_r+1)*(5.5.*L_C);
L_series=50*(1/(3*10^(8)))*sqrt(epsilon_re).*L_C;
R_s=1.5*10^(-6)*sqrt(2.6*10^9);
R_series=(4/3).*(L_C./(6.*W_C))*R_s;
end
disp(C_I)
disp(L_series)
disp(R_series)
0 Comments
Answers (1)
Image Analyst
on 21 Aug 2022
Is this what you want?
clc;
clear all;
close all;
W_C=[0.35 0.5 0.65 0.80];
L_C=[3 4.5 6 7.5];
H=0.035;
epsilon_r=3.38;
for i=1:length(W_C)
W=W_C(1,i);
for k=1:length(L_C)
L = L_C(k);
epsilon_o=8.85418782*10^(-12);
epsilon_re=0.5*(epsilon_r+1)+0.5*(epsilon_r-1)*(1+12*(H./W)).^(-0.5);
C_I=0.5*epsilon_o*(epsilon_r+1)*(5.5.*L);
L_series=50*(1/(3*10^(8)))*sqrt(epsilon_re).*L;
R_s=1.5*10^(-6)*sqrt(2.6*10^9);
R_series=(4/3).*(L./(6.*W))*R_s;
fprintf('W = %.2f, L = %.2f, C_I = %.6f, L_series = %.6f, R_series = %.6f\n', ...
W, L, C_I, L_series, R_series)
end
end
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!