Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Jeff
Jeff am 8 Apr. 2014
Bearbeitet: Oleg Komarov am 25 Aug. 2014
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

Antworten (1)

Walter Roberson
Walter Roberson am 8 Apr. 2014

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by