Specify format when using readtable() to read spreadsheet .xlsx?
조회 수: 11 (최근 30일)
이전 댓글 표시
Suppose my spreadsheet data.xlsx has a column of strings:
'abc', 'def', 'ghi'
Calling
myTable = readtable(data.xlsx)
puts each string into a cell array, like so:
{'abc'}, {'def'}, {'ghi'}.
The data cannot be accessed in the usual way, eg,
rows = myTable.Var1 == 'abc'
What I would like is each entry to be a string, without the cell-array wrapper. When I use the 'Format' option:
readtable(data.xlsx,'Format','%s'),
I get an error message:
Error using readtable (line 143).
Invalid parameter name: Format.
so it seems that the 'Format' option is not available for spreadsheets. Is this the case, or am I doing something wrong?
댓글 수: 0
채택된 답변
Peter Perkins
2016년 8월 4일
Cell arrays are the standard way to store strings in MATLAB. You may or may not be asking about character matrices, but you really don't want to be using those. Seeing myTable.Var1 == 'abc' in your post makes me think you may be asking about categorical arrays. It's easy to convert a cell array of strings to categorical, but you can't read directly to categorical from a spreadsheet.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!