Combine two column vectors when importing data from .csv into one

조회 수: 12 (최근 30일)
Samuel Bofferding
Samuel Bofferding 2020년 3월 5일
편집: Samuel Bofferding 2020년 3월 5일
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
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.
Samuel Bofferding
Samuel Bofferding 2020년 3월 5일
편집: Samuel Bofferding 2020년 3월 5일
This is the data. In this case i always need to combine each column "xxx1" with "xxx2" to create a third column.
I have been using the solution proposed by KSSV for the moment, which does give me the answer I want with a simple mathematic formula.

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2020년 3월 5일
Let A be integer and B be decimal
iwant = A+B/10 ;

Bhaskar R
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}, ',', '.'))

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by