Array indices must be positive integers or logical values.
조회 수: 7 (최근 30일)
이전 댓글 표시
I keep getting the error "Array indices must be positive integers or logical values" on every equation within the for loop and I'm not sure what I'm doing wrong. I've looked through other posts with this error and I can't seem to find my error
clear
clc
% Set known variables
rho = 800; % kg/m^3
mu = 0.00035; % N*s/m^2
Q = 2; % m^3/s
n = 25; % unitless
g = 9.81; % m/s^2
L = 160934; % m
m_dot = rho*Q;
H = L/(m_dot*g);
D = 1:0.1:10;
for n = 1:length(D)
P(D) = (128*mu*(Q^2)*L)./(pi*(D.^4));
CQ(D) = (P)./(rho*(n^3)*(D.^5));
CH(D) = (g*H)./((n^2)*(D.^2));
CQ(D) = Q./(n*(D.^3));
end
댓글 수: 0
답변 (1개)
madhan ravi
2020년 6월 2일
Left hand side of the equation (n) and in right hand side D(n).
And Ofcourse you don’t need a loop here ;)
댓글 수: 2
madhan ravi
2020년 6월 2일
% Set known variables
rho = 800; % kg/m^3
mu = 0.00035; % N*s/m^2
Q = 2; % m^3/s
n = 25; % unitless
g = 9.81; % m/s^2
L = 160934; % m
m_dot = rho*Q;
H = L/(m_dot*g);
D = 1:0.1:10;
n = 1:numel(D);
P = (128*mu*(Q^2)*L)./(pi*(D.^4));
CQ = P ./(rho*(n.^3).*(D.^5));
CH = (g*H)./((n.^2).*(D.^2));
CQ = Q./(n.*(D.^3));
참고 항목
카테고리
Help Center 및 File Exchange에서 Customize Object Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!