numel errors in matlab
조회 수: 4 (최근 30일)
이전 댓글 표시
hi,
im trying to write a program in matlab but i have some problems. there is some parts of my program. i hope you can help me.
-------------------------------------------------------------------
cd=xlsread('data.xlsx', 1, 'C3');
va=xlsread('veri.xlsx', 3, 'B3:B198');
d= xlsread('veri.xlsx', 3, 'C3:C198');
... and other datas
for i=1:1:198
wl(i,1)=0.5*ro*cd*a*(v(i,1)/3.6)^2;
...
w(i,1)=wl(i,1)+wr(i,1)+wb(i,1)+ws(i,1);
Ne(i,1)=w(i,1)*(va(i,1)/3.6)/(mv*1000);
...
n(i,1)=(va(i,1)/3.6)*60*ik(i,1)*ie/(2*pi*rd);
if n(i,1)>4500
g(i,1)=g(i,1)+1;
end
Nex=xlsread('data.xlsx', 4, 'C2:M2');
nx=xlsread('data.xlsx', 4, 'B3:B11');
bex=xlsread('data.xlsx', 4, 'C3:M11');
be(i,1)=interp2(Nex,nx,bex,Ne(i,1),n(i,1));
--------------------------------------------------------------------------
my first problem is;
??? Attempted to access n(2,1); index out of bounds because numel(n)=1.
Error in ==> tye at 82
if n(i,1)>4500
when i delete that line there is another same problem ;
??? Attempted to access n(2,1); index out of bounds because numel(n)=1.
Error in ==> tye at 87
be(i,1)=interp2(Nex,nx,bex,Ne(i,1),n(i,1));
what is my fault. please enlighten me.
thank you very much.
댓글 수: 0
답변 (3개)
Titus Edelhofer
2011년 12월 28일
Somewhere there is missing an "end", does the end of the for loop comes after the line "be(i,1) = interp2(...)"? Second: does a "clear" before running the code help?
Titus
댓글 수: 1
Titus Edelhofer
2011년 12월 28일
BTW, cd is not too good a choice for variable name because it's an important builtin function. That is not the reason of your problems though.
Matt Tearle
2011년 12월 28일
My guess is that your line
n(i,1)=(va(i,1)/3.6)*60*ik(i,1)*ie/(2*pi*rd);
is resulting in an empty array on the right-hand side. This would result in n having only one value (for i = 1). To verify, enter
dbstop if error
and run your code. It should stop and enter debug mode on the line that is causing the problem. Evaluate that right-hand side:
K>> (va(i,1)/3.6)*60*ik(i,1)*ie/(2*pi*rd)
You may also want to look at the variables you're referencing in that command: va, ik, ie and rd.
The whos command may also be of use.
댓글 수: 0
kosar akduman
2011년 12월 28일
댓글 수: 1
Matt Tearle
2011년 12월 28일
But your code has "for i=1:1:198". But, either way, the error message implies that the problem is occurring when i = 2.
Did you try dbstop if error? You can check the value of i when the error occurs and you go into debug mode.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!