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

2 views (last 30 days)
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

Image Analyst
Image Analyst on 11 Apr 2014
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
Image Analyst
Image Analyst on 12 Apr 2014
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.
Image Analyst
Image Analyst on 12 Apr 2014
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)

Community Treasure Hunt

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

Start Hunting!