Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
Jeff
Jeff le 8 Avr 2014
Modifié(e) : Oleg Komarov le 25 Août 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

Réponses (1)

Walter Roberson
Walter Roberson le 8 Avr 2014

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by