Index exceed matrix dimension error
2 ビュー (過去 30 日間)
古いコメントを表示
Leticia Campello
2015 年 11 月 27 日
回答済み: Walter Roberson
2015 年 11 月 27 日
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;
0 件のコメント
採用された回答
Walter Roberson
2015 年 11 月 27 日
Look more closely at your code. You have
v_flow(i,:)= v(i,:)./t(:,i);
m_flow(:,i)= v_flow(:,i)*de;
In the first line you write into the i'th row of v_flow, but in the second line you read from the i'th column of v_flow. If your v_flow does not happen to contain at least 4 columns then reading from the i'th column would be index exceeding matrix dimensions.
0 件のコメント
その他の回答 (1 件)
Geoff Hayes
2015 年 11 月 27 日
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 件のコメント
Geoff Hayes
2015 年 11 月 27 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!