Selecting specific columns to import from a CSV

조회 수: 1 (최근 30일)
Stanley Kubrick
Stanley Kubrick 2015년 2월 12일
답변: sathish kumar rb 2017년 11월 11일
The data I import from my GPS is formatted as CSV files with the following headers:
ID, Session_ID, Heading, Altitude, Latitude, Longitude, Created_DateTime
I only need the Latitude and Longitude values in columns 5 and 6. Is there any way of achieving this?
Currently I delete the last column manually in excel (Created_DateTime) and then use:
data = csvread('gps.csv',1,4);
This returns my latitude/longitude data but I'm wondering if there is a way of doing this without having to manually delete the Created_DateTime column in excel?

채택된 답변

dpb
dpb 2015년 2월 12일
fmt=[repmat('%*f',1,4) repmat('%f',1,2) '%*[^\n]'];
fid=fopen('gps.csv');
data=cell2mat(textscan(fid,fmt,'collectoutput',1));
fid=fclose(fid);
See
doc textscan % for details...
  댓글 수: 3
dpb
dpb 2015년 2월 12일
May need
'delimiter',','
for the CSV file
Stanley Kubrick
Stanley Kubrick 2015년 2월 12일
Actually just found a "Generate Script for Selection" under an Import button, thanks for your help though!

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

추가 답변 (1개)

sathish kumar rb
sathish kumar rb 2017년 11월 11일
hi need to select a specific colomns and rows copy one to another csv file how

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by