Textscan and csv fitness data problem
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Challenge: Convert attached csv-file into vectors for timestamps, power, and heart_rate data. The file originates from a FIT-file (from a fitness device) converted via FitSDKRelease into a CSV-file.
Problem: I am not able to generate an output via textscan that corresponds to the number of lines (rows) in the csv-file. E.g. the variable DataMat generated via examples below holds values from various rows in the first line (DataMat(1,:)). It is like some lines wrap around.
Example code
fileID = fopen(PathTargetFile,'rt');
Header = fgets(fileID); %line by line read
%....
LengthHeadder = 126;
StrReadFormat = repmat('%s',1,LengthHeadder);
Data = textscan(fileID, StrReadFormat, 'Delimiter', ',', 'ReturnOnError' , false);
DataMat = cell2mat(Data);
DataMat(1,:)
Another iteration:
fileID = fopen(PathTargetFile,'rt');
Header = fgets(fileID); %line by line read
%....
LengthHeadder = 126;
StrReadFormat = [repmat('%s',1,min(LengthHeadder,40)) '%*[^\n]'];
Data = textscan(fileID, StrReadFormat, 'Delimiter', ',', 'ReturnOnError' , false);
DataMat = cell2mat(Data);
DataMat(1,:)
0 comentarios
Respuestas (2)
Walter Roberson
el 1 de En. de 2018
Your input has 127 columns, not 126. Column 127 is empty where it exists at all -- but the fact that it exists is throwing off textscan, because textscan always picks up "mid-line" if the format did not use up the entire line.
4 comentarios
Walter Roberson
el 1 de En. de 2018
I have lost track of what the question is? The code I posted works on MATLAB; the behavior of Octave is mostly off-topic for this forum.
Jeremy Hughes
el 1 de En. de 2018
Hi Using textscan is great if you have files with varying formats or if you need certain special behaviors.
I found this one pretty straight forward with readtable and import options. Although it picks '/' for the delimiter.
opts = detectImportOptions(filename,'Delimiter',',','TextType','string');
opts.ExtraColumnsRule = 'ignore';
T = readtable(filename,opts);
head(T)
0 comentarios
Ver también
Categorías
Más información sobre QSP, PKPD, and Systems Biology en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!