MATLAB: How to ensure that the decimal separator in the CSV file matches the settings in MS Excel in MATLAB 8.0 (R2012b)

importMATLABseparatedxlsxlsx

I want to read in data from a CSV file on machines with different MS Excel settings for decimal separator and thousand separator. I want to implement a function that works on those different machines.

Best Answer

One possibility to accomplish this is to change the MS Excel seetings accordinly before reading the data and afterwards changing those settings back to its original values. For example if the decimal separator in the CSV file is ',' your solution could look as follows:
function [var_1,var_2,var_3] = ImportMeasuredData(ExcelFile)
% Check out the Microsoft office separator configuration on the machine.
MSconfig = actxserver('excel.application');
decimal_separator = MSconfig.DecimalSeparator;
thousand_separator = MSconfig.ThousandsSeparator;
% Change Microsoft office separator configuration to make it compatible with
% the CSV file (decimal separator must be ',' and thousand separator must be '.').
set(MSconfig, 'DecimalSeparator', ',');
set(MSconfig, 'ThousandsSeparator', '.');
% Import data form the csv file.
clear('var_1','var_2','var_3');
var_1 = xlsread(ExcelFile,'B2:B50000');
var_2 = xlsread(ExcelFile,'D2:D50000');
var_3 = xlsread(ExcelFile,'H2:H50000');
% Reset Microsoft configuration parameters to the origin.
set(MSconfig, 'DecimalSeparator', decimal_separator);
set(MSconfig, 'ThousandsSeparator', thousand_separator);
MSconfig.Quit;
MSconfig.release;
end