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 vue (au cours des 30 derniers jours)
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);
  1 commentaire
az
az le 16 Oct 2018
Modifié(e) : Walter Roberson le 16 Oct 2018
I am attaching the mat file as the code seems not looking good in the question. Thanks

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Oct 2018
for K = 1 : length(LL)
this_LL = LL(K);
this_mm = mm(K);
....
output(K) = result
end
  6 commentaires
Walter Roberson
Walter Roberson le 16 Oct 2018
There is no need to use K=1 before the for loop. Both variables will be stepped at the same time.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by