Array indices must be positive integers or logical values.

7 Ansichten (letzte 30 Tage)
Camille Molsick-Gibson
Camille Molsick-Gibson am 2 Jun. 2020
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

Antworten (1)

madhan ravi
madhan ravi am 2 Jun. 2020
Left hand side of the equation (n) and in right hand side D(n).
And Ofcourse you don’t need a loop here ;)
  2 Kommentare
madhan ravi
madhan ravi am 2 Jun. 2020
% 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));

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Customize Object Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by