numel errors in matlab

6 views (last 30 days)
kosar akduman
kosar akduman on 28 Dec 2011
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.

Answers (3)

Titus Edelhofer
Titus Edelhofer on 28 Dec 2011
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 Comment
Titus Edelhofer
Titus Edelhofer on 28 Dec 2011
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.

Sign in to comment.


Matt Tearle
Matt Tearle on 28 Dec 2011
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.

kosar akduman
kosar akduman on 28 Dec 2011
Titus Edelhofer i wrote "clear all, close all" before all codes. and there is no "end" problem with my iterations. thanks for answers but its not my answer.
Matt Tearle n(i,1) operation is resulting only 2 iterations. i mean it runs for i=1 and i=2.
  1 Comment
Matt Tearle
Matt Tearle on 28 Dec 2011
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!