Hello,
I'm coding to import several .txt files in matlab and create as many matrix as the number of file. I created the basic loop but I get stuck when it comes to store my dataArray without keeping overwriting it during the loop.
Here the code that I'm trying to work on to obtain new matrix in the workspace for each loop.
delimiter = '\t';startRow = 2;formatSpec = '%f%f%f%f%f%f%[^\n\r]';for k = 1:3 % Read the file.
textFileName = ['SJ' num2str(k) '.txt']; if exist(textFileName, 'file') fid = fopen(textFileName, 'rt'); dataArray = textscan(fid, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines' ,startRow-1, 'ReturnOnError', false); fclose(fid); else fprintf('File %s does not exist.\n', textFileName); end %Create matrix
GRFdata = [dataArray{1:end-1}];end
The issue is that GRFdata keeps overwriting whilst I would obtain GRFdata1, GRFdata2, etc.
Anyone could point me out the right way to proceed, please? Thanks
Best Answer