Convert german numbers from excel to matlab (change comma versus point)

I have copied a series of numbers from a German Excel. The comma is there as a decimal point. Now I want to read the numbers into Mathlab and I have also made a way. Unfortunately, it doesn't work with numbers of type xx,0x because I go over a two-column matrix and the leading zero in the second column disappears.
Is there a way to implement the following input in such a way that numbers are read in immediately?
Example:
experi=[
28,97
54,76
65,01
80,56
52,90
];
As result experi (or a converted array) should be real, like:
exper=[
28.97
54.76
65.01
80.56
52.90
];
Can anybody help me please?

2 Comments

How are you reading the data into MATLAB, what function or workflow (the Import Data tool in the Toolstrip?) are you using?
i have used google to find a solution. Normally it should possible to change such signs in strings. But i have a problem to read in this german numbers as strings.
This is my code:
experi=[
28,97
54,76
65,01
80,56
52,90
];
lauf=length(experi);
exper=zeros(lauf,1);
exper_orig=exper;
for i=1:lauf
c1s=string(experi(i,1))+"."+string(experi(i,2)); %here i will build the number but in the case of 65,01 the resulting number is 65.1
c1=double(c1s);
exper(i)=c1*10^atype(i);
end

Sign in to comment.

 Accepted Answer

You may try to use readtable to import your data. It reads excel files and has the option 'DecimalSeparator' that can be set to ','

4 Comments

Many thanks but readtable is not a option. I have very big tables and i need only a small part of this tables for evry run. For clearing: I am a chemist and i have data for 3 up to 25 molecules in different sheets. Many molecules differ in size and i have calculated the data using about 12 different ways. Now i need some of this data for one molecule at once. My method works for all of my data (95% of all) without a ",0" in the value. (I have found this problem after more then 50 runs.)
I don't want to force you to use readtable, but you can limit the data imported easily
myTable = readtable('myDataFile.xlsx','Sheet','SheetName','Range','A1:B2000');
Many thanks,
i will check this. Now its look good. With declering the range it can be useful for me.
Hello,
surprisingly readtable read numbers in a correct matter without declaring 'DecimalSeparator' (this gives an error). And using excel online one onedrive i can work with the matlab script and excel at the same time on the same document.
Many thanks

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!