xlsread returns NaN for cell references to string
이전 댓글 표시
I'm reading an excel document with xlsread with references to other cells that be either text or numeric values. The problem is that xlsread seems to interpret cells starting with an "=" as numeric even if is a reference to a cell with text. Thus the result of a reference to text cell returns NaN, even in the raw format. Is there any way to work around this? I've tried some tricks (see below) that forces Excel to treat the cell as text but it doesn't work with xlsread. The (very) simple example below illustrates the issue. Example:
A B C D
1 My age is 10
2 =A1 =B1&"" =TEXT(C1;0) =D1
> [num text raw] = xlsread('book1.xls')
num =
NaN NaN NaN 10
NaN NaN NaN 10
text =
1×3 cell array
'My' 'age' 'is'
raw =
2×4 cell array
'My' 'age' 'is' [10]
[NaN] [NaN] [NaN] [10]
Matlab 2016b, Excel 2010 (xls format), Linux.
댓글 수: 9
jean claude
2017년 10월 12일
Anders Bergåker
2017년 10월 12일
Fangjun Jiang
2017년 10월 12일
For your information, I tried this:
MATLAB R2016b
Windows 7
Excel 2010
Excel file saved as .xls (Excel 97-2003 Workbook)
The cell is read as its value, not NaN. For example, my cell C1 is "=SUM(A1:B1)" but it was read as its numeric value.
Anders Bergåker
2017년 10월 12일
Image Analyst
2017년 10월 12일
If it's a string (enclosed in double quotes), it's a string, and will/should return a string. If you get rid of those double quotes, it will treat it as a formula and should return the numbers, like Fangjun got.
Anders Bergåker
2017년 10월 13일
Fangjun Jiang
2017년 10월 13일
FYI, with your example file, xlsread() returns value, not NaN or formula. Maybe you should report this to the Mathworks tech support.
>> [num, text, raw] = xlsread('test.xls')
num =
[]
text =
1×2 cell array
'Hello' 'Hello'
raw =
1×2 cell array
'Hello' 'Hello'
Walter Roberson
2017년 10월 13일
The behavior is different in basic mode, which is for any system that is not windows with excel installed. The poster mentioned basic mode and Linux.
Anders Bergåker
2017년 10월 16일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!