Importing values from excel
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I'm trying to import datas from Excel to Matlab by using xlsread. my problem is that, it doesn't bring all of the values to command window but I can see the values in Workspace.It says NaN for cells such as 'DFX' or '78669-87'. I can't use import data all the time because the excel file needs to be updated everyday. So what I need is a code which can bring every values in each update to MaTLAB Is there another way to bring the datas? or any recommendation? Thank you:)
回答(1 个)
dpb
2018-8-6
"...It says NaN for cells such as 'DFX' or '78669-87'."
As rightfully it should for numeric values; those aren't numbers but text in those cells.
If your data file format isn't regular you have to have some way to know which data are in which rows/columns to be able to interpret it correctly; xlsread will bring back every cell in the third (optional) output and you can parse it from there...
[n,t,r]=xlsread(...
n is the data which could be read as numeric, t is the text and r is the "raw" content of all cells of whatever type as a cell array from which one can tell exactly where any given piece of information is(*) for parsing the content programmatically.
It's much simpler if you can regularize the spreadsheet itself first.
(*) I think mayhaps behavior is different than was but will need to verify for your version in that the size of the n and r arrays originally was NOT the same as for r so that finding the location of a field label in r didn't actually correlate to where in n it's associated values actually were. I believe that has been fixed, but as noted you'll need to verify behavior to be sure.
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!