Iterate over two arrays
34 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Image Analyst
2022 年 8 月 21 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!