Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Jeff
Jeff el 8 de Abr. de 2014
Editada: Oleg Komarov el 25 de Ag. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 8 de Abr. de 2014

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by