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!