Index exceed matrix dimension error
Mostrar comentarios más antiguos
Everytime time that I run my code, this error ocurrs:
Index exceeds matrix dimensions.
Error in analyse_lbbc (line 17)
m_flow(:,i)= v_flow(:,i)*de;
what should I do ? Thank You
function [v_flow,m_flow,v1,F_1,F_2,F_1_mean,F_2_mean]= analyse_lbbc(m,v,t);
%create some variable
m=[0.4 0.3 0.2 0.1];
v=[0.003;0.003;0.003;0.003];
t=[11.3 11.8 16.8 20.4];
%save the variable m,v,t into one *.mat file
save data.mat m v t
%load the data
load data.mat
d= 0.005; %diameter
de=0.001; %density of the water
g=9.81; %gravity
A=(pi/4)*(d^2); %cross section area of the nozzle
c=0
for i=1:4
v_flow(i,:)= v(i,:)./t(:,i);
m_flow(:,i)= v_flow(:,i)*de;
v1=v_flow(:,i)*A;
F_1= m(:,i)*g;
F_2= m_flow(:,i).*v1(:,i);
end
F_1_mean = mean(:,1:4);
F_2_mean= mean(:,1:4);
c=F_1_mean - m(:,1:4)*F_2_mean;
Respuesta aceptada
Más respuestas (1)
Geoff Hayes
el 27 de Nov. de 2015
Leticia - the error message Index exceeds matrix dimensions is telling you that the code is trying to access an element within a matrix using an index that exceeds the dimensions of that matrix. So put a breakpoint at line 17 (or your code)
m_flow(:,i)= v_flow(:,i)*de;
and call your function. When the debugger pauses at this line look at the value of i and the dimensions for m_flow and v_flow. Does accessing the ith column of v_flow make sense?
2 comentarios
Leticia Campello
el 27 de Nov. de 2015
Geoff Hayes
el 27 de Nov. de 2015
Leticia - when you step through the code, what are the dimensions of m_flow and v_flow? What is the i that is causing the problem? I don't have access to your data so cannot comment on why you are observing this error or whether another function is needed.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!