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!