storing values in matrix
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a script wherein I have two nested for loops. The first for loop goes into a series of five directories. The second for loop goes into files within the directories and performs a series of analyses on waveforms. I'm trying to store certain values each time the script makes a loop through one directory. There's something wrong with my syntax obviously because instead of creating a new column for each directory its just adding onto the column the new values for the subsequent directories. I'm having difficulties getting it to start a new column when it stores. Any help would be much appreciated! Here's an example of a value I'm wanting to store:
keep2=[]
for i=1:length(dirs)
for pp=1:length(files)
keep(:,pp)=(snr510(:,pp)>1)&(snr1015>1)&(snr1520)>1;
keep2=[keep2;keep(:,pp];
end
end
Again instead of storing the values each time I move through the loop into a new column it just adds onto keep2.
0 comentarios
Respuesta aceptada
Jan
el 26 de Jul. de 2011
Do the directories have the same number of files? Then a 3D-array would be fine:
keep = zeros(1, length(dirs), length(files)); % Pre-allocate!
for i=1:length(dirs)
for pp=1:length(files)
keep(:, i, pp) = (snr510(:,pp)>1) & (snr1015>1) & (snr1520)>1;
end
end
If the directories have a different number of files, you need a CELL:
keepC = cell(1, length(dirs));
for i=1:length(dirs)
keep = zeros(size(snr510, 1), length(files));
for pp=1:length(files)
keep(:, pp) = (snr510(:,pp)>1) & (snr1015>1) & (snr1520)>1;
end
keepC{i} = keep;
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Time-Frequency Analysis 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!