xlsread read numbers as txt

5 views (last 30 days)
Alexander Magnusson
Alexander Magnusson on 18 Mar 2016
Commented: Walter Roberson on 5 Dec 2017
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
Alexander Magnusson
Alexander Magnusson on 18 Mar 2016
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.
Walter Roberson
Walter Roberson on 21 Mar 2016
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
somayyah jurair
somayyah jurair on 18 Mar 2016
In that case check cell format in xls file it may be text that is why MATLAB is importing it as text
Alexander Magnusson
Alexander Magnusson on 21 Mar 2016
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.


Ahmet Aloglu
Ahmet Aloglu on 5 Dec 2017
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
Walter Roberson
Walter Roberson on 5 Dec 2017
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.

Community Treasure Hunt

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

Start Hunting!