Hi all,
I've done the below code to read .txt files and extracting columns from each one. the error appears just from the second to the rest of files. Could anyone help me with this?
thank you
Error using fgets
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in RUV_readFile (line 21)
line = fgets(file1);
clc
clear all
close all
files_str = fileread('foldername/files.txt');
list = splitlines(files_str);
for k=1:length(list)
filename = list{k};
disp(filename);
file1 = fopen(strcat('foldername',filename));
filemat = [];
line = fgets(file1);
while ischar(line)
if isempty(strfind(line,'%'))
vec = str2num(line);
filemat = [filemat;vec];
end
line = fgets(file1);
end
fclose(file1);
cols = filemat(:,1:4);
save(strcat('output/',filename), 'cols', '-ascii')
end