save loop data with non integer steps
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Torsten
2023-2-21
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 个)
John D'Errico
2023-2-21
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!