save loop data with non integer steps

2 vues (au cours des 30 derniers jours)
Jerry
Jerry le 21 Fév 2023
Commenté : Jerry le 21 Fév 2023
I have following script and I am trying to save the results of the loop in an array. I get following error message:
Array indices must be positive integers or logical values.
How can I save the results in an array even though my steps are not integer values?
reduced_scattering_coeff = 10;
absorbing_coeff = 1;
source_detector_distance= 1.5;
refection_parameter= 3.25;
pi = pi;
detectorsignal=zeros(size(0.01:0.01:1));
for absorbing_coeff = 0.01:0.01:1
mu_t = reduced_scattering_coeff+absorbing_coeff;
mu_eff = sqrt(3*(reduced_scattering_coeff+absorbing_coeff));
r1 = sqrt(((1/mu_t)^2)+source_detector_distance);
r2 = sqrt((((4/3*refection_parameter+1)/mu_t)^2)+(source_detector_distance^2));
detectorsignal= (1/(4*pi*mu_t))*((mu_eff+1/r1)*((exp(mu_eff*r1))/r1^2)+((4/3*refection_parameter)+1))*(mu_eff+1/r2)*((exp(-mu_eff*r2))/(r2^2));
detectorsignal(absorbing_coeff)= detectorsignal;
end

Réponse acceptée

Torsten
Torsten le 21 Fév 2023
reduced_scattering_coeff = 10;
absorbing_coeff = 1;
source_detector_distance= 1.5;
refection_parameter= 3.25;
absorbing_coeff = 0.01:0.01:1;
detectorsignal = zeros(size(absorbing_coeff));
for i=1:numel(absorbing_coeff)
mu_t = reduced_scattering_coeff+absorbing_coeff(i);
mu_eff = sqrt(3*(reduced_scattering_coeff+absorbing_coeff(i)));
r1 = sqrt(((1/mu_t)^2)+source_detector_distance);
r2 = sqrt((((4/3*refection_parameter+1)/mu_t)^2)+(source_detector_distance^2));
detectorsignal(i)= (1/(4*pi*mu_t))*((mu_eff+1/r1)*((exp(mu_eff*r1))/r1^2)+((4/3*refection_parameter)+1))*(mu_eff+1/r2)*((exp(-mu_eff*r2))/(r2^2));
end
plot(absorbing_coeff,detectorsignal)
  1 commentaire
Jerry
Jerry le 21 Fév 2023
this works perfectly, thank you!

Connectez-vous pour commenter.

Plus de réponses (1)

John D'Errico
John D'Errico le 21 Fév 2023
acvalues = 0.01:0.01:1;
detectorsignal=zeros(size(acvalues));
for ind = 1:numel(acvalues)
absorbing_coeff = acvalues(ind);
% stuff. you should get the idea...
detectorsignal(ind)= (1/(4*pi*mu_t))*((mu_eff+1/r1)*((exp(mu_eff*r1))/r1^2)+((4/3*refection_parameter)+1))*(mu_eff+1/r2)*((exp(-mu_eff*r2))/(r2^2));
end

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by