Array indices must be positive integers or logical values.

1 vue (au cours des 30 derniers jours)
Luke Witherow
Luke Witherow le 28 Fév 2022
Commenté : Star Strider le 28 Fév 2022
for i = 1:dt:tEmpty
heightArray(1,i) = sqrt(h1) - (.5 * k .* timesArray(i))^2;
flowRateArray(1,i) = sqrt(2 * g .* heightArray(1,i));
massFlowRateArray(1,i) = exitHoleArea * p .* flowRateArray(1,i);
end
Here is the Error message I am getting.
Array indices must be positive integers or logical values.
Error in Luke_Witherow_hw4>drainTank_Loop (line 53)
heightArray(1,i) = sqrt(h1) - (.5 * k .* timesArray(i))^2;

Réponse acceptée

Star Strider
Star Strider le 28 Fév 2022
Try this —
iv = 1:dt:tEmpty;
for i = 1:numel(iv)
heightArray(1,i) = sqrt(h1) - (.5 * k .* timesArray(i))^2;
flowRateArray(1,i) = sqrt(2 * g .* heightArray(1,i));
massFlowRateArray(1,i) = exitHoleArea * p .* flowRateArray(1,i);
end
I am guessing that ‘dt’ is not an integer, and that is throwing the error.
.
  2 commentaires
Luke Witherow
Luke Witherow le 28 Fév 2022
Thank you, this worked!
Star Strider
Star Strider le 28 Fév 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by