dlmwrite with specific titles in loop

1 Ansicht (letzte 30 Tage)
Robert
Robert am 23 Okt. 2015
Beantwortet: Walter Roberson am 23 Okt. 2015
I have the following code
%96 Matrices are loaded above and grouped as "A1"
A1Janstack = cat (3,A11,A113,A125,A137,A149,A161,A173,A185)
A1Febstack = cat (3,A12,A114,A126,A138,A150,A162,A174,A186)
A1Marstack = cat (3,A13,A115,A127,A139,A151,A163,A175,A187)
A1Aprstack = cat (3,A14,A116,A128,A140,A152,A164,A176,A188)
A1Maystack = cat (3,A15,A117,A129,A141,A153,A165,A177,A189)
A1Junstack = cat (3,A16,A118,A130,A142,A154,A166,A178,A190)
A1Julstack = cat (3,A17,A119,A131,A143,A155,A167,A179,A191)
A1Augstack = cat (3,A18,A120,A132,A144,A156,A168,A180,A192)
A1Sepstack = cat (3,A19,A121,A133,A145,A157,A169,A181,A193)
A1Octstack = cat (3,A110,A122,A134,A146,A158,A170,A182,A194)
A1Novstack = cat (3,A111,A123,A135,A147,A159,A171,A183,A195)
A1Decstack = cat (3,A112,A124,A136,A148,A160,A172,A184,A196)
A1Janmean = mean (A1Janstack,3)
A1Febmean = mean (A1Febstack,3)
A1Marmean = mean (A1Marstack,3)
A1Aprmean = mean (A1Aprstack,3)
A1Maymean = mean (A1Maystack,3)
A1Junmean = mean (A1Junstack,3)
A1Julmean = mean (A1Julstack,3)
A1Augmean = mean (A1Augstack,3)
A1Sepmean = mean (A1Sepstack,3)
A1Octmean = mean (A1Octstack,3)
A1Novmean = mean (A1Novstack,3)
A1Decmean = mean (A1Decstack,3)
A1Jananoms = bsxfun(@minus, A1Janstack, A1Janmean)
A1Febanoms = bsxfun(@minus, A1Febstack, A1Febmean)
A1Maranoms = bsxfun(@minus, A1Marstack, A1Marmean)
A1Apranoms = bsxfun(@minus, A1Aprstack, A1Aprmean)
A1Mayanoms = bsxfun(@minus, A1Maystack, A1Maymean)
A1Junanoms = bsxfun(@minus, A1Junstack, A1Junmean)
A1Julanoms = bsxfun(@minus, A1Julstack, A1Julmean)
A1Auganoms = bsxfun(@minus, A1Augstack, A1Augmean)
A1Sepanoms = bsxfun(@minus, A1Sepstack, A1Sepmean)
A1Octanoms = bsxfun(@minus, A1Octstack, A1Octmean)
A1Novanoms = bsxfun(@minus, A1Novstack, A1Novmean)
A1Decanoms = bsxfun(@minus, A1Decstack, A1Decmean)
directory = pwd
cd ('anomolies\NDVI')
for k=1:12
individual_matrix = A1Jananoms(:,:,k);
fname = sprintf('NDVIanom%04d.txt',k);
dlmwrite (fname,individual_matrix)
end
The last part of my code needs to be changed. As it stands it will write the 12 files, A1Jananom0001.txt, A1JanAnom0002.txt and so fourth.
As you can probably tell from my code the data is monthly matrices over 8 years. So I need a way to print the data as A1JanAnom0001.txt, A1JanAnom0013.txt, A1JanAnom0025.txt etc, so as to keep the data chronologically correct. I am unsure how to do this.
Thank you in advance for any advice

Antworten (1)

Walter Roberson
Walter Roberson am 23 Okt. 2015
Change
fname = sprintf('NDVIanom%04d.txt',k);
to
fname = sprintf('A1Jananom%04d.txt',k);

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by