Combine two column vectors when importing data from .csv into one
11 次查看(过去 30 天)
显示 更早的评论
As an export from a sensor I have my data in a .csv data. However, the .csv data separates in two different columns the values of the integer and the decimal point. When importing the data I would like to merge these two columns and seperate them with a decimal point. I do not know how this works. I have already tried combining the two vector columns using sscanf(sprintf(...)) and dividing it by 100, however the amount of digits in my decimal part (Column B) is not consistently the same.
A B
0 15
1 2
3 12
0 02
What I would like to have as a result is:
C
0.15
1.2
3.12
0.02
Can anyone give me some advice?
Thanks! :)
2 个评论
Guillaume
2020-3-5
Can you attach an example of the csv file. Possibly, the problem can be fixed by a better import rather than trying to fix it after the fact.
回答(2 个)
Bhaskar R
2020-3-5
f = fopen('your file name.csv', 'r') %
data = textscan(f, '%s');
fclose(f);
your_data = cellfun(@str2num, strrep(data{1}, ',', '.'))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!