Index exceeds matrix dimensions problem

1 次查看(过去 30 天)
I am geting '__Index exceeds matrix dimensions_' problem, while running the following function with input:
vanRijn(21,0.0005,0.002,2650,1000,0.2,0.9)
Where can my mistake be?
function [m_b]=vanRijn(T,d_50,d_90,den_s,den_w,R,v_m)
%%step1
nu=0.00000178/(1+0.0337*T+0.000221*T^2);
d_g=d_50*(9.81*(den_s-den_w)/den_w/nu^2)^(1/3);
%%step 2 Shields parameter
if d_g<=4
theta_cr=0.24*d_g^(-1);
elseif d_g>4 && d_g<=10
theta_cr=0.14*d_g^(-0.64);
elseif d_g>10 && d_g<=20
theta_cr=0.04*d_g^(-0.10);
elseif d_g>20 && d_g<=150
theta_cr=0.013*d_g^0.29;
else
theta_cr=0.055;
end
v_cr=sqrt(theta_cr*(den_s-den_w)/den_w*9.81*d_50);
%%step 3 chezy coeficient
C_prime=18*log10(12*R/3/d_90);
%%step 4
v_0_ef=sqrt(9.81)*v_m/C_prime;
%%Step 5
transp=(v_0_ef^2-v_cr^2)/v_cr^2;
%%step 6
m_b=0.053*(transp^2.1)/(d_g^0.3)*den_s*sqrt(9.81*(den_s-den_w)/den_w)*d_50^1.5;
  1 个评论
Jan
Jan 2011-10-28
The complete error message contains the line, which causes the error. Please consider and post such important details.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2011-10-28
The shown code runs fine on my computer and replies 0.68863.
Did you edit the code and forgot to save? Do you have mutliple files with this name in the PATH?
which vanRijn -all
Did you create a function file called "sqrt.m" or "log10.m"? Anyhow, using the debugger with the command Fangjun has suggested already, is the best idea. Usually the debugger is even more efficient than this forum.
Just a remark:
if d_g<=4
theta_cr=0.24*d_g^(-1);
% elseif d_g>4 && d_g<=10
elseif d_g<=10 % Better! d_g <= 4 is excluded already

更多回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-10-28
It happens when you try to do this for example.
>> a=rand(2,3)
a =
0.131973292606335 0.956134540229802 0.059779542947156
0.942050590775485 0.575208595078466 0.234779913372406
>> b=a(4,5)
??? Index exceeds matrix dimensions.
Run your code step by step or type in
dbstop if error
and then run your code to find out where it happened and then why it happened.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by