isolate separate portions of a ASCII/TEXT FILE which have results for different time stamps

조회 수: 1 (최근 30일)
i have an ascii file which can be read as text file in matlab
this file contains a number of columns (say 10 or 11) with different names(headers given in the file.
these columns are produced after different time intervals.
so basically, i have a different set of results in different separate sections of the file
What i WANT?? : I want to write these sections into separate files and read each of these columns in order to plot graphs etc.
plz help me guys
thanks in advance
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 8월 28일
regexp() to delete the first line. Then regexp() 'ZONE', 'split' . After that you can textscan() each block
shadman khan
shadman khan 2019년 9월 22일
I tried this code. But not getting the result.
fileID = fopen('Plot_Copy','r');
temp2 = regexp(fileread('Plot_Copy'), 'ZONE', 'split');
C = textscan(fileID,'%f',34);
fclose(fileID);
Can you please help me for using textscan?

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 9월 22일
filename = 'Plot_Data_Elem.txt';
fileblocks = regexp(fileread(filename), 'ZONE', 'split');
nblocks = length(fileblocks);
vstr = regexprep(fileblocks{1}, 'Variables\s*=\s*', '', 'once');
vstr = regexprep(vstr, '\s*$', '', 'once'); %in case of trailing whitespace
vars = regexp(vstr, '\s+', 'split');
nvars = length(vars);
fmt = repmat('%f', 1, nvars);
C = cell(nblocks-1,1);
for K = 2 : nblocks
C{K-1} = array2table(cell2mat(textscan(fileblocks{K}, fmt, 'HeaderLines', 1, 'CollectOutput', true)), 'VariableNames', vars);
end
With that example file, this gives an 8 x 1 cell array, each entry of which is a 12 x 16 table object with each column labeled according to the variables mentioned in the first line of the input file.
  댓글 수: 1
shadman khan
shadman khan 2019년 9월 25일
my goodness
this couldn't have been done in a better way
all i need o now, irs to store eah of this 12x16 table object into a different file and i am done...
thanks Robert

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by