Why am I receiving the error message "Array indices must be positive integers or logical values"?
Show older comments
Hello, I am getting stuck on computing one of the components of a model that I am working on. Attempting to compute the component u_z returns the error "Array indices must be positive integers or logical values." I am stumped on what is going wrong as the other component, u_r, is being computed and returning an array with no problems. Attached below is the code and the error:
% Define parameters
R = 5000;
r_max = 45;
z_max = 4000;
ch_o = z_max / 0.22;
ch_i = ch_o / 12.5;
sf = r_max / (0.2357 * R);
r = -2000:0.1:2000;
z = 6000;
% Plot results
plot(r, Compute_u(R, ch_o, ch_i, sf, r, z))
function u = Compute_u(R, ch_o, ch_i, sf, r, z)
u_r = ((sf * R^2)./(2 .* r)) .* (1-exp(-(r./R).^2)) .* (exp(-(z/ch_o))-exp(-(z/ch_i)));
u_z = (-(sf .* exp(-(r./R).^2))) .* (ch_i(exp(-(z/ch_i))) - ch_o(exp(-(z/ch_o))-1));
u = sqrt(u_r^2 + u_z^2);
end
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!