Array indices must be positive integers or logical values

2 ビュー (過去 30 日間)
Mikel Gonzalez Bribiesca
Mikel Gonzalez Bribiesca 2020 年 12 月 3 日
When I try to save the "t" and "v" values into the x(i) and y(i) vectors, I keep getting th same mistake. "Array indices must be positive integers or logical values."
Im trying to save tha value of each itiretation so I can plot all of them, anyone got another solution for this?
clc;
clear;
clc;
h=.12
rtanque=.1
rsalida=.005
g=9.806;
for i = (h:-.01:.00001)
Vol=(pi.*rtanque.^2).*i;
v=(2.*g.*i).^(1/2)
Q=(2.*(pi.*rsalida.^2)).*v;
t=Vol/Q
x(i)=t
y(i)=v
end
plot(x,y);
xlabel('Tiempo en [s]')
ylabel('Velocidad en [m/s]')
title('Gráfica Velocidad vs Tiempo')
grid on;
hold on;

回答 (1 件)

VBBV
VBBV 2020 年 12 月 3 日
clc;
clear;
clc;
h= linspace(0.00001,0.12,12)
rtanque=.1
rsalida=.005
g=9.806;
for i = 1:length(h)
Vol=(pi.*rtanque.^2).*i;
v=(2.*g.*i).^(1/2)
Q=(2.*(pi.*rsalida.^2)).*v;
t=Vol/Q
x(i)=t
y(i)=v
end
plot(x,y);
xlabel('Tiempo en [s]')
ylabel('Velocidad en [m/s]')
title('Gráfica Velocidad vs Tiempo')
grid on;
hold on;
  1 件のコメント
Mikel Gonzalez Bribiesca
Mikel Gonzalez Bribiesca 2020 年 12 月 3 日
Thank you so much!
Would there be a way to make the loop start from h until 0 (or almost 0). The program is supposed to measure the time it takes for a bucket of water to drain, so that would make a bit more sense. But thank you a lot.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by