Effacer les filtres
Effacer les filtres

Saving summed matrixes seperately after a for loop

1 vue (au cours des 30 derniers jours)
FeAde
FeAde le 7 Avr 2015
Modifié(e) : Matt J le 7 Avr 2015
Hi all:
I have this code that is working but just needs a little help. I am doing summing of 12 variables in a (struct frame of 12 files) repeatedly until the end. I want the results to be saved with increment filenames or unique identifiers, but it keeps on overwriting the previous operations. Thanks in advance and credit to Jason who helps edited the initial code:
dirname = uigetdir;
Files = dir(fullfile(dirname,'*.mat'));
N = length(Files);
count = 0;
for i = 1:N
if count == 0
Total = zeros(1800,3600);
end
count = count + 1;
FileData = load(fullfile(dirname, Files(i).name));
Total = Total + FileData.gpm.Frame;
count = count + 1;
if count == 12
filename = sprintf('%s_%d','Total',count); % what I want to do here is to be saving the files separately with unique identifier after each operation, but instead it keeps on over-writing.
save(filename);
count = 0;
end
end

Réponses (1)

Matt J
Matt J le 7 Avr 2015
Modifié(e) : Matt J le 7 Avr 2015
It's not overwriting. The if statement
if count == 12
ensures that your operation of interest will only ever be done in the single case when count==12. Perhaps you should remove it from the if...end block.

Catégories

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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by