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

1 view (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 8 Apr 2014

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!