How to save 7 different large matrix (for Landsat 7 bands) in one variable?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
In this MATLAB code i want to save the surface reflectance for all the bands i.e., 7 bands in surface_Reflectance1 variable. The matrix size of one band is 7321*7351. So can you please suggest me how to save all the bands in one variable name.?
for dates1 =1:121
for bands = 1:7
if exist(fullfile(filepath1,date1(dates1).name,'L2C2'), 'dir')
date_dir1 = dir(fullfile(filepath1,date1(dates1).name,'L2C2'));
ImB1file1 = dir(fullfile(filepath1,date1(dates1).name,'L2C2','*B1.TIF'));
Imfiles1_N = dir(fullfile(filepath1,date1(dates1).name,'L2C2',[ImB1file1.name(1:end-5),num2str(bands),'.TIF']));
[A1, R] = geotiffread(fullfile(Imfiles1_N.folder,Imfiles1_N.name));
Mtl2 = dir(fullfile(filepath1,date1(dates1).name,'L2C2','*MTL.txt'));
[MTL_list1,value] = MTL_parser_L8(fullfile(Mtl2.folder,Mtl2.name));
RMUL1 = 0.0000275;
RADD1 = -0.2;
Surface_Reflectance1(:,bands) = (RMUL1)*(single(A1))+(RADD1);
end
end
end
2 Commenti
dpb
il 4 Ott 2022
Makes no sense...you wrote "The matrix size of one band is 7321*7351." but in
Surface_Reflectance1(:,bands) = (RMUL1)*(single(A1))+(RADD1);
variable bands is 1, 2, ..., 7 subsequently so Surface_Reflectance1(:,bands) is and can only be a Nx7 array. Where are the other 7351-7 columns supposed to be coming from?
Risposte (1)
Bjorn Gustavsson
il 4 Ott 2022
Break down your loops into something simpler first. Skip the outermost one and select one date that you know you have data from.
Also change your coding style, at least for the loop-variables. It is a mess to read date1(dates1) - that will be a source for unnecessary headakes. Change dates1 to i_date, or idx_dates just to make it clear what is the dates-array and what is the indices into that array. This will make a big difference in the long run.
% for i_dates =1:121
i_dates = 12; % if you have dat from that date
for bands = 1:7
if exist(fullfile(filepath1,date1(i_dates).name,'L2C2'), 'dir')
date_dir1 = dir(fullfile(filepath1,date1(i_dates).name,'L2C2'));
ImB1file1 = dir(fullfile(filepath1,date1(i_dates).name,'L2C2','*B1.TIF'));
Imfiles1_N = dir(fullfile(filepath1,date1(i_dates).name,'L2C2',...
[ImB1file1.name(1:end-5),num2str(bands),'.TIF']));
[A1, R] = geotiffread(fullfile(Imfiles1_N.folder,Imfiles1_N.name));
Mtl2 = dir(fullfile(filepath1,date1(i_dates).name,'L2C2','*MTL.txt'));
[MTL_list1,value] = MTL_parser_L8(fullfile(Mtl2.folder,Mtl2.name));
RMUL1 = 0.0000275;
RADD1 = -0.2;
% Something like this will save a 7321 x 7351 image A1 into Surface_reflectance
% for each band.
Surface_Reflectance1(:,:,bands) = (RMUL1)*(single(A1))+(RADD1);
end
end
HTH
3 Commenti
Bjorn Gustavsson
il 5 Ott 2022
My suggestion is that you save data from separate dates into different directories. Something like this:
for iDate = 1:numel(Dates)
currDirname = datestr(Dates(iDate,:),'yyyymmdd'); % or whatever format suits you
mkdir(currDirname)
% reading data
% processing data
savefile = sprintf('My-process.mat')
savename = fullfile(currDirname,savefile)
save(savename,'Surface_Reflectance1') % add other variables, or whatever
end
HTH
Community
Più risposte nel Power Electronics Control
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!