save loop data with non integer steps

2 visualizzazioni (ultimi 30 giorni)
Jerry
Jerry il 21 Feb 2023
Commentato: Jerry il 21 Feb 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

Risposta accettata

Torsten
Torsten il 21 Feb 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)

Più risposte (1)

John D'Errico
John D'Errico il 21 Feb 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

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by