How can I make iteration of 2 for loops of 2 variables of same length, so that output will be the same length of input variables, not their multiplication.

조회 수: 1 (최근 30일)
Hello here I am attaching the code I am running. If I iterate only one variable say LL keeping another variable mm constant value, then the outpot ,that is S_s runs well with the same length of input vector LL. But if I iterate both input vector LL and mm then the output gets LL*mm dimension. actually LL and mm are related, that is for every LL value there is a mm value. I just want when the code is running for one particular LL value, then just pick that corresponding mm value. Then go for another LL and mm values and so on, and store the output S_s for every set of LL mm pair. Thanks.
interploation_Points = 100;
a= [2, 4, 10, 133, 211, 314, 1000,1.3*10^3];
L= linspace(min(a),max(a),interploation_Points);
M= [-0.617030303030302 + 0.396013468013468i,-75.9774643403734 + 9.26989211985172i,-151.337898377717 + 18.1437707716900i];
m = linspace(min(M),max(M),interploation_Points);
i=1;
% j=1;
% for La = min(L):interploation_Points: max(L)
for LL = 1:length(L)
% mm = -0.617030303030302 + 0.396013468013468i;
for mm= 1:length(m)
k = (2* pi ./LL);
x = (5 .* k);
z =10.* pi.*(mm ./LL);
n_max = round(x + 4.05 .*(x) .^(1/3) + 2);
n = 1:n_max;
s_x = besselj(n+0.5,x);
s_z = besselj(n+0.5,z);
a = (s_z - mm .* s_x )./(s_x - mm .* s_z);
S_s(i) = 2*pi./ k .^2 .* (sum ((2*n+1) .* (abs(a) .* abs(a))));
LL = LL + 1;
mm=mm+1;
i = i+1;
% j = j+1;
end
end
plot(LL, S_s);

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 16일
for K = 1 : length(LL)
this_LL = LL(K);
this_mm = mm(K);
....
output(K) = result
end
  댓글 수: 6
Walter Roberson
Walter Roberson 2018년 10월 16일
There is no need to use K=1 before the for loop. Both variables will be stepped at the same time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by