read data from files in a loop and append into one array

조회 수: 3 (최근 30일)
smo
smo 2016년 7월 10일
답변: Image Analyst 2016년 7월 10일
Hi,I have a number of files, each contains 2columns but varies number of rows.
I set up a loop to read the data from each of them. Now, I want to put the read-out-data append to an array (so at the end the array will have n-rows x 2-columns). how can I do that please? below I have listed the code I have for reading the data. Many thanks.
filenum = 2;
for i=1:filenum
f = load(['output_' num2str(i) '.txt']) %load the datafiles:
%output_1.txt, output_2.txt,...etc
%here, want to add all the 'f' here into an array
end
example: file1
11 22
33 44
file2
22 33
55 66
77 88
array want:(if call it NewArray)
NewArray =
11 22
33 44
22 33
55 66
77 88

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 10일
편집: Azzi Abdelmalek 2016년 7월 10일
filenum = 2;
M=[];
for ii=1:filenum
name=sprintf('output%d_%dstd.txt',ii,stdtimes)
M=[M;dlmread(name)]
%here, want to add all the 'f' here into an array
end
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 10일
편집: Azzi Abdelmalek 2016년 7월 10일
filenum = 2;
M=[];
for ii=1:filenum
name=sprintf('output_%d.txt',ii)
M=[M;dlmread(name)]
end
smo
smo 2016년 7월 10일
thank you very much.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 7월 10일

카테고리

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

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by