fopen files in one dataset
Afficher commentaires plus anciens
Hi!
I collected two different data sets from 30 subjects, so in total I have 60 different .txt files. My goal is to have them all in one big dataset, already in order. The files have different endings (_MT or _OT), depending on the coniditon. Each subject should therefore appear twice within the dataset, but already labeled with 0 or 1 for the condition. I tried to go with a for loop.
for ssubj = 001:030
filename = ['VP0', num2str(ssubj), '_MT.txt'];
filename2 = ['VP0', num2str(ssubj), '_OT.txt'];
file = fopen('/Users/cf/Documents/MATLAB/Passive');
tmp = textscan(file, '%s%f%f%f', 'CollectOutput', true, 'Delimiter', ' ', 'HeaderLines', 3);
[~] = fclose(file);
dat(: , 1, ssubj) =
end
I always get this error... Or is the directory already wrong?
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Thank you for your help!
5 commentaires
Mathieu NOE
le 14 Déc 2020
hi
could you share some data files (both extensions)
Mathieu NOE
le 14 Déc 2020
I will not repeat Rik's comment below
this is probably what you intended to do :
bside that , you can add your specific folder by using fullfile :
for ssubj = 001:030
filename = ['VP0', num2str(ssubj), '_MT.txt'];
filename2 = ['VP0', num2str(ssubj), '_OT.txt'];
% get data from first file
fid = fopen(filename);
out1 = textscan(fid, '%s%f%f%f', 'CollectOutput', true, 'Delimiter', ' ', 'HeaderLines', 3);
[~] = fclose(fid);
% get data from second file
fid = fopen(filename2);
out2 = textscan(fid, '%s%f%f%f', 'CollectOutput', true, 'Delimiter', ' ', 'HeaderLines', 3);
[~] = fclose(fid);
% process the data
% dat(: , 1, ssubj) = ;
end
TS
le 14 Déc 2020
Rik
le 14 Déc 2020
Are you sure the files exist? You don't check if they exist.
You can check if Matlab is able to open the file by checking if the fid is above 0.
Mathieu NOE
le 14 Déc 2020
you can , at least, test my code in the same directory of your data files
it should work , because this is very basically what I did
then, if you need to access your data from different folder(s) use fullfile with the folder / directory info
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Text Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!