why do i keep getting index exceeds matirx dimensions?

I just typed in simple codes for plotting a graph and i keep getting the same error why is that?
d=1:1:10
theta=pi/4;
Dc= d/2.*(1-cos(theta));
Q= (2.^(3/2).*Dc.^(5/2).*sqrt(g).*(theta-0.5.*sin(2.*theta)).^(3/2))/(8.*sqrt (sin(theta).*(1-cos(theta).^(5/2))))
subplot (2,1,2);
plot (d,Q)
title('17473981')
xlabel('diameter')
ylabel('flow rate')
grid on

 Réponse acceptée

the cyclist
the cyclist le 1 Avr 2012

1 vote

What is "g"? If I set g=1, your code works for me.
Might you have accidentally define your own variable named "cos", "sin", or "sqrt", so MATLAB thinks it is indexing a variable?

4 commentaires

parsh
parsh le 1 Avr 2012
yeah, i forgot value of g
g=9.8
but i still get the same error, the error is in the labels and title somehow. if i do xbale = something
than it works but i do not get and labels on graph
thanks.
What happens if you restart MATLAB and type in those exact lines?
parsh
parsh le 1 Avr 2012
umm... it works. :) thank you so much
Glad it worked, but that drastic solution does not necessarily help you understand where you went wrong. My best guess is that maybe you accidentally defined a new variable (maybe "xlabel") and MATLAB was trying to access that instead of the built-in function.

Connectez-vous pour commenter.

Plus de réponses (1)

Rick Rosson
Rick Rosson le 1 Avr 2012

0 votes

Please post the exact error message and indicate which line is triggering the error.

3 commentaires

parsh
parsh le 1 Avr 2012
the exact error is
"Index exceeds matrix dimensions."
and it comes up when i define the title and lables
Funny - I get "Undefined function or variable 'g'."
parsh
parsh le 1 Avr 2012
yeah i forgot to put in the value of g, my mistake. thanks you

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by