Reading a complex CSV file and converting to MAT
Afficher commentaires plus anciens
Hi all,
I'm trying to read in a large CSV file that has been exported from Vicon Nexus -- with 3D motion capture data -- with as minimal modification to the original exported file as possible (TestData.CSV accessed here -- attache) .
From what I've read, .MAT file would be the best file to convert to but because of the header info and the 2 separated sets of data in the same file -- "TRAJECTORIES" and "FORCE PLATES" -- I believe the only option I have is to use textscan. I need to use both sets of data and index an unknown number -- experimenting -- of columns & row.
Eventually I only want to read in the variables that are needed, which are located in different columns and in both of the two different data sets. The two different data sets are best exported into the 1 CSV file to contain all the variables needed for further analysis down the line. Is it possible to use textscan in this case? Any help would be much appreciated. Cheers.
6 commentaires
Star Strider
le 13 Nov 2017
per isakson
le 13 Nov 2017
Modifié(e) : per isakson
le 13 Nov 2017
per isakson
le 13 Nov 2017
Modifié(e) : per isakson
le 13 Nov 2017
I didn't know that Vicon Nexus exists, but my first reaction was to google "Vicon Nexus matlab". These two links were among the top five. They show an ambitious support/integration of Matlab. Maybe they also provide means to transfer data via files to Matlab.
"From what I've read, .MAT file would be the best file to convert to" yes, why not, but you have to it in steps.
- Decide how you want to store the data in variables in Matlab
- Read and parse the csv-file
- Save to a mat-file
Regarding the second step see https://se.mathworks.com/matlabcentral/answers/365496-parse-text-file#answer_290758
>> str = fileread( 'TestData.csv' );
>> whos str
Name Size Bytes Class Attributes
str 1x2015360 4030720 char
>> [ n,s,r] = xlsread( 'TestData.csv' );
>> whos n s r
Name Size Bytes Class Attributes
n 0x0 0 double
r 3882x1 4449976 cell
s 3882x1 4449976 cell
>> s(20)
ans =
'Field #,X,Y,Z,X,Y,Z,X,Y,Z,X,Y,Z,X,Y,Z,X,Y,Z,X,Y,Z,X,Y,…'
xlsread seems to read your file line by line without parsing anything. (Matlab R2016a)
per isakson
le 13 Nov 2017
Modifié(e) : per isakson
le 13 Nov 2017
"Nexus has an Offline Data SDK specifically designed to allow users to push and pull specific items of data into MATLAB" Whatever that is?
James
le 20 Nov 2017
Réponses (1)
Hi James!
I am dealing with the same kind of csv-files and was wondering if you could help me out here. I managed to import the file using readtable. However, now I can't find a possibility to detect where the needed variables are in this table.
find(T=={'FORCE PLATES'})
gave the error 'Undefined operator '==' for input arguments of type 'table'.' Hope you or someone else here can help me out.
Thanks!
5 commentaires
Hi James, thanks a lot for your quick answer! As I don't have access to Nexus either, I also need to work with Matlab. How do you trim csv files? I have over 300 files that want to be analysed... Also, did you manage to import it as csv? I first had to save it as a xlsx because with the csv file, matlab says
'Error using readtable (line 198) Reading failed at line 153. All lines of a text file must have the same number of delimiters. Line 153 has 22 delimiters, while preceding lines have 1.
Note: readtable detected the following parameters: 'Delimiter', ',', 'HeaderLines', 151, 'ReadVariableNames', false, 'Format', '%f%q''
Thanks again! Jule
Jule
le 10 Jan 2018
Re Error: Since I only have real patient data, I'm not allowed to upload it here. But my csv is very similar to yours. I have the sections ANALYSIS, EVENTS, ANALOG and FORCE PLATE. With every file, the error occurs at the line under 'ANALOG'. Matlab is right saying that there is only one comma ('800.000000,Hz'), however the same appears in the line under 'TRAJECTORIES' (l. 18 in your example file) without producing an error there. Interestingly, if I delete the problematic line, readtable works but deletes everything above said line. Matlab seems to think everything above this is header. That does not happen with the xlsx files.
James
le 10 Jan 2018
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!