If your importfile()
function works correctly, in this manner at every for-loop iteration you'll overwrite a
with the most recent imported file. You should concatenate all your files (i.e. matrices) instead.
A matrix concatenation can either be done by rows (i.e. horizontal concatenation) or by columns (i.e. vertical concatenation). As I understand, you want a vertical concatenation in order to generate a unique matrix with 144 columns and as many rows as your single files contain.
Thus you should change the loop as follows
myMatrix=[];
for fileNum=1:8;
startRow=1;
endRow=72;
filename
myMatrix=[myMatrix ; importfile(filename, startRow, endRow)];
end
The vertical concatenation can be done by means of the ;
operator, thus an instruction like A=[B ; C]
will create a matrix A
by concatenating matrices B
and C
. In your case you initialize myMatrix
as empty and then you will vertically concatenate (in an iterative fashion) all outputs from importfile()
, that are your .tsv
files.
At the end of the loop, myMatrix
should have size NxM
where M
is 144 and N
is the sum of the number of rows across all your files (8*72).
Update
If you have to pass explicitly the filename to the importfile()
function you can create a cell array of strings in which each element of the cell is a filename. Thus in our case the cell array will be something like:
filenames={'filename1.tsv','filename2.tsv',...,'filename8.tsv'};
obviously you must replace the strings inside the cell with the proper filenames and finally you can slightly edit the loop as follows
myMatrix=[];
for fileNum=1:8;
startRow=1;
endRow=72;
myMatrix=[myMatrix ; importfile(filenames{i}, startRow, endRow)];
end
In this manner, at every loop iteration the i-th filename will be given as input to importfile()
and hopefully it'll be loaded.
For this to work you should (let's make things simple)
- place your Matlab script and obviously the function
importfile()
in the same folder containing your .tsv files
- set said folder as the Current Folder
or if you have the .tsv files in a given folder and your scripts in another folder, then the Current Folder must certainly will be the folder containing your scripts and the filenames inside the cell array filenames
must contain the entire path, not just the proper filenames.