xlsread read numbers as txt
Show older comments
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
on 18 Mar 2016
Edited: Andrei Bobrov
on 18 Mar 2016
Please give example your xlsx file with small part of your data
Alexander Magnusson
on 18 Mar 2016
Edited: Walter Roberson
on 18 Mar 2016
Walter Roberson
on 18 Mar 2016
If that is your csv file, then the "[" and "]" would signal that the column is text rather than numeric.
Alexander Magnusson
on 18 Mar 2016
Walter Roberson
on 21 Mar 2016
Could you attach a copy of it for testing ?
Answers (2)
somayyah jurair
on 18 Mar 2016
Edited: somayyah jurair
on 18 Mar 2016
0 votes
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
Alexander Magnusson
on 18 Mar 2016
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
on 21 Mar 2016
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
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?
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!