how do i load 100 txt files to a cell array and use specific data entries in each file to build a variable vector
조회 수: 1 (최근 30일)
이전 댓글 표시
how do i load 100 text files (1height-0000, 1height-0001, 1height-0002,1height-0003, 1height-0004 ...................) to a cell array and access the entries on the 18th row of first column. i want to create a new variable called height with each entry making up a 100 x 1 column vector. The entries are space sperated as shown below:
The code i have written so far brings back an error...
clear
name = "1height-000%d.txt";
numfiles = 99;
mydata = cell(1, numfiles);
for k = 1:numfiles
myfilename = sprintf(name, k);
mydata{k} = importdata(myfilename);
end
I will appreciate an urgent assistance.....Thanks in Anticipation
댓글 수: 0
답변 (1개)
Jalaj Gambhir
2019년 11월 12일
Hi,
Assuming you want to process all files and store the numerical value in the 18th line of each file to a 100x1 double vector, you can try the following code:
clear
name = "1height-000%d.txt";
numfiles = 100;
height = zeros(100,1);
mydata = cell(1, numfiles);
for k = 1:numfiles
myfilename = sprintf(name, k-1);
fid = fopen(myfilename);
linenum = 18;
C = textscan(fid,'%s',1,'delimiter','\n', 'headerlines',linenum-1);
height(k) = str2double(C{:});
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Other Formats에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!