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!