Array indices must be positive integers or logical values.

조회 수: 7 (최근 30일)
Camille Molsick-Gibson
Camille Molsick-Gibson 2020년 6월 2일
댓글: Camille Molsick-Gibson 2020년 6월 2일
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

답변 (1개)

madhan ravi
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
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 CenterFile Exchange에서 Customize Object Indexing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by