Importing data from Delsys Trigno software .csv
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I am trying to create a single header from a .csv file exported from Trigno Discover software from delsys.
I have attached a small section of the .csv file as it had to be under 5MB to upload but it should show what i am trying to do.
I am welcome to suggestions on how to handle the variable naming more elegantly but essentially i want my header to be:
header = [LSOL, LSOLgx,LSOLgy,LSOLgz,LKneeGonio1,LKneeGonio2,RKneeGonio1,RKneeGonio2,Analog11,Analog12,Analog13,Analog14, Analog21,Analog22, Analog23, Analog24]
This way my gyroscope variables say from which sensor they came from and i have channels 1 and 2 for each goniometer. The analog data isnt' as important but the way i named them for example: is to have Analog24 be "Analog2,channel4".
I was trying to merge the two arrays in matlab and then use scripts to remove values in () but quickly realized this would be a jumbled mess.
Any help on this would be greatly appreciated.
3 comentarios
Peter Perkins
el 17 de Jul. de 2023
Your description seems to have very little to do with the filew you attached. which is an xlsx, not a csv, and which has something like half a million blank rows.
Respuestas (2)
Vinayak Gupta
el 1 de Jun. de 2023
Hi Ines,
As per my understanding you want to translate two variable rows into one. And then process them to modify text as per the inner content. As there maybe different instances for each sensor type and you wish to follow different conventions for each, you will need to process all the types individually.
Your comments hints towards that you have already combined the variable names into one row. But to help others who may find it useful, I have included the code for importing and combining rows also.
As you say, you are using a csv, but have uploaded an .xlsx file. I have added code for both the types of files.
% Incase of an excel file
data = readtable('Trial_2.csv.xlsx','ReadVariableNames',false,'DataRange','A4');
data(2,:)=[];
% Incase of a csv
data = readtable('Trial_2.csv', 'ReadVariableNames', false);
% Extract row 1 with repetetions
row = table2cell(data(1,:));
nonEmptyCells = ~cellfun('isempty', row);
newRow = row(nonEmptyCells);
newRow = repelem(newRow, diff([find(nonEmptyCells), length(row)+1]));
%Extract row 2
row2 = table2cell(data(2,:));
% Concat with '_' or any other symbol
finalRow = strcat(newRow,'_',row2);
% Remove content inside paranthesis and spaces
finalRow = regexprep(finalRow, '\s*\([^)]*\)\s*', '');
finalRow = regexprep(finalRow, '\s*', '');
%Rename 'AnalogX_AnalogY' to 'AnalogXY'
finalRow = regexprep(finalRow, '^(Analog\d+)\_Analog(\d)$', '$1$2');
% You can use regexp to match specific requirements
% and add code for each type of sensor naming
data.Properties.VariableNames = finalRow;
data(1,:) = [];
data(2,:) = [];
After I have imported the data. I have modified row 1 to include repetitions of the previous column in empty ones. Then, I have concatenated the values to row2.
After that we use "regexprep" to replace content within parenthesis and any spaces.
I have added regex to modify 'AnalogX_AnalogY' to 'AnalogXY' as you suggested. You can write code for other sensor names as desired.
You can read mode about readtable here:
And more on regexprep here:
1 comentario
Peter Perkins
el 17 de Jul. de 2023
I recommend not doing any of this. At best, it's code that the author is guessing might work around the obvious bad file that's attached.
Peter Perkins
el 17 de Jul. de 2023
If you really have a csv, if it really has variable names spread over two lines, user NumHeaderLines to tell readtable to skip everything up to the actual data, then read those var names lines in some other fashion. Then make the names whatever you want, and assign them to the table's VariableNames property.
0 comentarios
Ver también
Categorías
Más información sobre Whos 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!