Iterate over two arrays
조회 수: 36 (최근 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!