Attempted to access X(1). Unable to acces because numel(X)=0

Hi,
I am trying to write a code that selects a portion of an array read from a .csv file by promptimg the user to input the first entry and last entry. But I get the error:
"Attempted to access X(1). Unable to acces because numel(X)=0"
And the full array is not formed. This is a portion of the code:
Y=xlsread('Book1.xlsx', 'a1:a500')
prompt = ' What is first? ';
f1 = input(prompt);
prompt= 'What is last number? ';
f2 = input(prompt);
y=[(Y(f1)):Y(f2))]
any ideas?

 Accepted Answer

You do not have an array X in that code, so how could you have gotten that error message? Please GIVE ALL THE RED TEXT . Don't snip or paraphrase like you did. We want it all : line numbers, traceback, code statements, everything .

3 Comments

So this is my test code and it is giving the same error:
C = xlsread('H:\Book1.xlsx','a1:ak200');
x1=(C(:,4));
prompt = 'What is first number? ';
f1 = input(prompt);
prompt= 'What is last number? ';
f2 = input(prompt);
X1=[x1(f1):x1(f2)]
y=interp1(X1,[1:18]);
This is the error I'm getting: X1 =
Empty matrix: 1-by-0
Attempted to access X(1); index out of bounds because numel(X)=0.
Error in interp1 (line 160) extptids = Xq < X(1) | Xq > X(end);
Error in test (line 16) y=interp1(X1,[1:18]);
Why is X1 coming out an empty matrix?
anna's "Answer" moved here:
the reason I'm paraphrasing is b/c I do not have matlab access nor access to the file at the moment so this is what I know from memory. However, I do not have a "X" array at all in my file. But the error does indicate an "X". The array it is not forming is the "y" array. Everything before that is fine.
This does not make much sense:
X1=[x1(f1):x1(f2)]
What if f1=4 and f2=30 and x1(4) = 123.456, and x1(30) = 43.2? What do you want X1 to be?
Maybe you want X1 to be the subarray from element f1 to element f2. In that case you'd do
X1 = x1(f1:f2);

Sign in to comment.

More Answers (0)

Asked:

on 11 Apr 2014

Commented:

on 12 Apr 2014

Community Treasure Hunt

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

Start Hunting!