- in Excel, select the whole column with the boolean TRUE or FALSE
- under the tab panel Data > Text To Columns > Next > Next
- select Text (Column data format) > Finish
- Now use [a,b,raw] = xlsread(...)
How do I prevent XLSREAD from converting TRUE to 1 and FALSE to 0 in MATLAB R2011a?
4 views (last 30 days)
Show older comments
When I attempt to read the and Excel file using xlsread(filename) I get the following output:
[M,T,R] = xlsread('Sample.xls')
M =
0 1
T =
'Heading 1' 'Heading 2' 'Heading 3'
'Data 1 ' 'Data 1 ' 'Data 1 '
'Data 2' 'Data 2' 'Data 2'
'Data 3' 'Data 3' 'Data 3'
'Data 4' '' ''
'Data 4' 'true' 'false'
'Data 5' 'Data 6' 'Data 7'
'Data 6' 'Data 7' 'Data 8'
R =
'Heading 1' 'Heading 2' 'Heading 3'
'Data 1 ' 'Data 1 ' 'Data 1 '
'Data 2' 'Data 2' 'Data 2'
'Data 3' 'Data 3' 'Data 3'
'Data 4' [ 0] [ 1]
'Data 4' 'true' 'false'
'Data 5' 'Data 6' 'Data 7'
'Data 6' 'Data 7' 'Data 8'
MATLAB is interpreting FALSE and TRUE as Boolean variables as they are imported, but not when they are lower case.
This is true even though the cell format for the entire worksheet has been explicitly set to "Text"
Accepted Answer
MathWorks Support Team
on 13 Jun 2013
This happens due to the functionality of Excel.
1. typing in excel true converts the value to 1 (boolean true) if any numeric or general format is selected
2. typing in excel true when the format was preselected to text, keeps the string (thus importing with xlsread keeps the string)
3. having typed true with numeric or general format and then converting to text format does not affect the saved value unless you press F2 then Enter. Unfortunately this last operation is applicable to single cells.
In order to workaround this follow the steps below:
0 Comments
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!