필터 지우기
필터 지우기

Can you help to create a new variable on each loop?

조회 수: 3 (최근 30일)
Jeff
Jeff 2014년 4월 8일
편집: Oleg Komarov 2014년 8월 25일
Hi All,
I would like to have a new "data" variable below to be created on each iteration of this loop - length(files) = 12; My end goal is to then create one cell array with the portion extracted out of each text file.
Below works fine for just one text file but I would like to loop for each file and end up having say
data_1 = {1 2 3 4};
data_2 = {5 6 7 8};
data_3 = {9 10 11 12};
data = [data_1;data_2;data_3]
Much appreciated, Jeff
p.s Image if you see this I hope you realize I am building from previous work
-----------------------------------
files = dir(*.txt');
for j = 1:length(files)
filename(j,:) = char(files(j,:).name);
fid(j,:) = fopen(filename(j,:), 'r');
end
filename = cellstr(filename);
for j = 1:length(fid);
tline = fgetl(fid(j));
k=1;
while ischar(tline)
disp(tline)
findrows = and(strfind(tline, 'ARR++'),strfind(tline,':20134:'));
if ~isempty(findrows)
data{k,:} = tline(:);
k=k+1;
end
tline = fgetl(fid(j));
end
clear tline m n;
fclose(fid(j));
end

답변 (1개)

Walter Roberson
Walter Roberson 2014년 4월 8일

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by