Importing data from Delsys Trigno software .csv

25 Ansichten (letzte 30 Tage)
Ines Shekhovtsov
Ines Shekhovtsov am 17 Mai 2023
Beantwortet: Peter Perkins am 17 Jul. 2023
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 Kommentare
Ines Shekhovtsov
Ines Shekhovtsov am 18 Mai 2023
Hi, if you look at the .csv file, you'll see that the variable names that are exported are on two seperate lines. The EMG variables and a few others are on line 4 while gyroscope variables are on line 6. I can manually create a header array and have already done that for a few of my scripts but i was hoping i could get the software to read the .csv file and import those variables for me. But as i mentioned they are on different lines so i am unsure how to code for that in an elegant manner. I have extracted lines 4 and 6 from the .csv file and merged the two together in a new array. That works but i also wish to rename the variables and am wondering what a good unique solution to that would be. I hope that makes sense and thank you for your time.
Peter Perkins
Peter Perkins am 17 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Vinayak Gupta
Vinayak Gupta am 1 Jun. 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 Kommentar
Peter Perkins
Peter Perkins am 17 Jul. 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.

Melden Sie sich an, um zu kommentieren.


Peter Perkins
Peter Perkins am 17 Jul. 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.

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by