Keeping record of Number of concatenated files

조회 수: 1 (최근 30일)
ARN
ARN 2019년 4월 17일
편집: Stephen23 2019년 5월 2일
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.
2019-04-17_14h42_57.png
  댓글 수: 4
Adam Danz
Adam Danz 2019년 4월 17일
Stephen Cobeldick's solution does what you're asking.
Stephen23
Stephen23 2019년 4월 29일
편집: Stephen23 2019년 4월 29일
"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.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2019년 4월 17일
편집: Stephen23 2019년 4월 17일
Inside your loop:
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{:})
  댓글 수: 9
ARN
ARN 2019년 5월 2일
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...:)
Stephen23
Stephen23 2019년 5월 2일
편집: Stephen23 2019년 5월 2일
" 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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by