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!