Array indices must be positive integers or logical values

2 visualizaciones (últimos 30 días)
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;

Respuestas (1)

VBBV
VBBV el 3 de Dic. de 2020
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 comentario
Mikel Gonzalez Bribiesca
Mikel Gonzalez Bribiesca el 3 de Dic. de 2020
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.

Iniciar sesión para comentar.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by