An EEG dataset .txt , I want to transpose the rows and columns for all files.

3 views (last 30 days)
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
Rabeah A
Rabeah A on 7 Sep 2023
Actually I'm new to MATLAB and I have a running code that deals with EEG files such as rows are channels. that's way I want to change them.

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 7 Sep 2023
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
EEG = 18204×3
1703509 1326511 1528584 1711498 1334520 1536615 1705921 1328796 1531118 1694223 1317011 1519531 1692689 1315472 1517843 1703451 1326439 1528569 1711428 1334467 1536607 1705938 1328835 1531153 1694351 1317151 1519643 1692668 1315488 1517863
EEGT = EEG.' % Transposed
EEGT = 3×18204
1703509 1711498 1705921 1694223 1692689 1703451 1711428 1705938 1694351 1692668 1703313 1711312 1705773 1694428 1692821 1703274 1710918 1705693 1694156 1692196 1702908 1711174 1706023 1694625 1692823 1703394 1711520 1706029 1694092 1692186 1326511 1334520 1328796 1317011 1315472 1326439 1334467 1328835 1317151 1315488 1326314 1334344 1328729 1317221 1315551 1326341 1334171 1328823 1317164 1315211 1326062 1334344 1329054 1317561 1315857 1326618 1334725 1329054 1316944 1315122 1528584 1536615 1531118 1519531 1517843 1528569 1536607 1531153 1519643 1517863 1528429 1536389 1530985 1519640 1517866 1528451 1536228 1531088 1519478 1517266 1527826 1536129 1531097 1519718 1517921 1528464 1536523 1531081 1519127 1517216
You can also use the transpose, .' function for this.
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
Star Strider
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.)

Sign in to comment.


Abderrahim. B
Abderrahim. B on 3 Sep 2023
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!