Keeping record of Number of concatenated files

ARN (view profile)

on 17 Apr 2019
Latest activity Edited by Stephen Cobeldick

on 2 May 2019

Stephen Cobeldick (view profile)

I am vertically concatinating some .mat files and i want to keep the track record of how many files i have concatinated;
Like putting 1 infront of values of file 1 (13780x1) and 2 infront of values of 2 (13840x1). Is there a way to do that?
Attached is the pic of random values; 3 files (15x1) concatinated so i want the left or the right answer.

Show 1 older comment
ARN

ARN (view profile)

on 17 Apr 2019
i did it manually in excel? Need a method to do that in MATLAB.

on 17 Apr 2019
Stephen Cobeldick's solution does what you're asking.
Stephen Cobeldick

Stephen Cobeldick (view profile)

on 29 Apr 2019
"I am vertically concatinating some .mat files ..."
I doubt that: .mat files are a binary file format, it does not make much sense to concatenate them. You can certainly import their contents into MATLAB and concatenate those.

Stephen Cobeldick (view profile)

on 17 Apr 2019
Edited by Stephen Cobeldick

Stephen Cobeldick (view profile)

on 17 Apr 2019

N = ... the total number of files.
C = cell(1,N)
for k = 1:N
M = ... import the matrix here.
M(:,end+1) = k;
C{k} = M;
end
Z = vertcat(C{:})

on 29 Apr 2019
+1 for the 'neat' structure option. Nice and tidy.
ARN

ARN (view profile)

on 2 May 2019
Hi,
Thanks for the answer. Sorry for asking late, but this method is good for concatination of one matrix while i have got 30. That is why, i was creating the structure afterwards. Any suggestions on that...:)
Stephen Cobeldick

Stephen Cobeldick (view profile)

on 2 May 2019
" Any suggestions on that..."
Sure: using the code from my earlier comment, simply call fieldnames on T and then add a nested loop over those fields.
Then inside the nested loop add the extra column. After the nested loop allocate T to C.
Or, if you are feeling particularly adventurous, write something using structfun.