An EEG dataset .txt , I want to transpose the rows and columns for all files.
Show older comments
I have an EEG dataset .txt files (55 files) , each file contains 3 columns and hundreds of rows. I want to change all .txt files to 3 rows and hundreds columns (transpose ).
2 Comments
Star Strider
on 3 Sep 2023
It is easier in MATLAB to keep them as they are now. I would not change them.
Rabeah A
on 7 Sep 2023
Answers (2)
I would still keep them as they are in the files, and transpose them after you read the files.
EEG = readmatrix('S9 HC.txt') % Original
EEGT = EEG.' % Transposed
In MATLAB there are two kinds of matrix transposition, ‘normal’ transposition (.') and complex conjugate transposition provided by the ctranspose, ' function ('). For real numbers, these are equivalent, however not for complex numbers. For N-dimensional matrices, there is also pagetranspose, that does a non-conjugate transposition, and for good measure, I will introduce you to the permute function.
.
9 Comments
Rabeah A
on 10 Sep 2023
Star Strider
on 10 Sep 2023
Just do it in your code for each file you import, just after importing it. Leave the files themselves as they are.
Rabeah A
on 10 Sep 2023
Edited: Walter Roberson
on 10 Sep 2023
Star Strider
on 10 Sep 2023
I do not understand what you are doing, however it does not appear to be correct.
You need to import the files, probably using readmatrix or a similar function, before you can do anyting with their contents. I do not see that anywhere.
.
Rabeah A
on 10 Sep 2023
Star Strider
on 10 Sep 2023
I still do not understand where in your code you are importing the data in the files.
Could you upload an example file so that I can see how your code works?
Rabeah A
on 10 Sep 2023
Star Strider
on 10 Sep 2023
Please upload a representative EDF file here. If that is not a valid file type, use the zip function to enclose it in a .zip file and then upload that.
I will also need the entire code of the ‘SegmentEEGIntoInstances’ function so I can see what you are doing with the file.
(I do not do anything offline. I keep everything here so it all makes sense, if anyone else has similar problems and needs to see this solution.)
Walter Roberson
on 10 Sep 2023
Abderrahim. B
on 3 Sep 2023
0 votes
Hi!
You can try a for loop, however there is a better way to do this is to use tabularTextDatastore(location) and then use readall function to read all the file, later on you can transpose and do whatever you want with the readall function output.
Let me know if this helps.
Abderrahim
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!