Saving a preallocated matrix within a nested for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Code is below. I am trying to save the SpectroBey matrix before the nested loop to correspond with the files that are being pulled in within the first loop. So in the end, I would like to have saved SpectroBey1, SpectroBey2, Spectrobey3....and so on.
for j=1:6
SpectroBey=[];
for jj=1:length(tslide)
g=exp(-width*(t-tslide(jj)).^2);
Pg=g.*P; Pgf=fft(Pg);
SpectroBey=[SpectroBey;abs(fftshift(Pgf))];
end
[m,n]=size(SpectroBey);
SpectroBey=reshape(SpectroBey,m*n,1);
save(sprintf('SpectroBey%d', j), 'SpectroBey')
end
0 Kommentare
Antworten (1)
Jan
am 6 Mär. 2015
Bearbeitet: Jan
am 6 Mär. 2015
Your code does explicitly not use a pre-allocation. Therefore the tag and the title is misleading. The code contains a lot of details, which do not concern the question. It is more convenient for the readers if you concentrate on the problem.
As far as I understand your message (what exactly is your question?). all you need is this line:
save(sprintf('SpectroBey%d', j), 'SpectroBey')
You find further details if you read the FAQ section: How to process files in a loop. Ask your favorite search engine for "Matlab FAQ" or search in this forum.
Siehe auch
Kategorien
Mehr zu Startup and Shutdown 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!