Why do I receive an empty array when I read a CSV file with XLSREAD in MATLAB 7.10 (R2010a)?
4 ビュー (過去 30 日間)
古いコメントを表示
I have some data in a CSV file (comma separated values) and I am reading it into MATLAB using the following code:
data = xlsread('name_of_file.csv');
[m, n] = size(data);
The output I receive is an empty matrix with 'm=0' and 'n=0'. Why is this happening when my file is not empty?
採用された回答
MathWorks Support Team
2013 年 9 月 12 日
The reason why an empty array is generated when reading a CSV file using XLSREAD in the following way:
data = xlsread('name_of_file.csv');
might be due to the language and regional settings on the computer.
If this is the case, it can be visualised by reading the data in the following way:
[data, text] = xlsread('name_of_file.csv');
Then, all the numeric data values will be written as text in the variable 'text'.
In some regional settings the commas are used to mark the decimal positions in numbers whereas in CSV files they are used to separate the data values. In those regional settings XLSREAD is not able to recognize numbers and reads all the data as text.
In order to avoid this issue, a possible workaround is to change the language settings to English. The language/regional settings can be accessed via the 'Control Panel' on a Windows machine.
If changing the regional settings is not an option, it is possible to import the data from the CSV file directly using the Import Wizard by clicking on 'File'->'Import Data'. When the Import Wizard window opens, there is a check box that says 'Generate MATLAB Code' at the bottom of the window. By clicking on it, some MATLAB code will be generated that can be run to import CSV files automatically. Then, by saving the generated function as, for example, IMPORTDATA, it will be possible to import CSV files automatically without having to click on 'File'->'Import Data' by typing
importdata('name_of_file.csv');
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!