xlsread read numbers as txt

I used [Num,Txt,Raw]=xlsread to import a vector that only contains zeros and ones. The problem is that "Num" do not get a single value. The numbers gets read as text and Txt gets all the values. Anyone that have an idea how to fix this? I have used the same technique on same type of vectors before but just this one is not so nice to me.

5 Comments

Andrei Bobrov
Andrei Bobrov on 18 Mar 2016
Edited: Andrei Bobrov on 18 Mar 2016
Please give example your xlsx file with small part of your data
[1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0]
If that is your csv file, then the "[" and "]" would signal that the column is text rather than numeric.
Its just a sample of my vector. I added the [] when printing it here. The column in excel is just excisting of zeros and ones. Even if it was text in the column, Num of [Num,Txt,Raw] should still take all the numbers of the vector and Txt the rest. I have done this correct in other vectors containing different numbers and it works all fine, but just this vector gets read as text because some strange reason.
Could you attach a copy of it for testing ?

Sign in to comment.

Answers (2)

somayyah jurair
somayyah jurair on 18 Mar 2016
Edited: somayyah jurair on 18 Mar 2016
If your xls file only contain numeric values then use: num=xlsread(filename) while if it has both numeric as well as string data use [num,text]=xlsread(filename,sheet). You can later assign variables to your imported data using a=num(:,1) b= text(:,1) depending upon the column number of your imported data

3 Comments

That doesnt work. I usually import the data that way but in this case I only got num=[].
In that case check cell format in xls file it may be text that is why MATLAB is importing it as text
I have done that too and it have the same format as the other vectors that work to import to matlab. The text is formated as general and I have tried to change it to number as well but it is still the same problem that is happening.

Sign in to comment.

Somehow I have encountered this same problem. I had used exact same code for my previous runs, and they worked smoothly. Today, this problem occurred to my excel data. I found out that somehow xlsread reads the numbers as text, and store them into a cell array. So I just used
x1 = str2double (x)% x is the cell array that stored numbers as text.
to convert my cell array to double so now I have the extracted numbers from excel files. Just wanted to share this as a way to overcome this problem, unless there would be a better way to solve it.

1 Comment

Would it be possible to attach a sample file for testing?
Also, are you using MS Windows with Excel (Office) installed?

Sign in to comment.

Asked:

on 18 Mar 2016

Commented:

on 5 Dec 2017

Community Treasure Hunt

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

Start Hunting!