How to save 7 different large matrix for 165 dates (for Landsat 8 bands) in one variable?

1 Ansicht (letzte 30 Tage)
In this code I want to save the value of "(RMUL1)*(single(A1))+(RADD1)" in the Surface_Reflectance1 variable. The size of A1 is 7321*7351 for every band. If I run this code for 1 date then, I am able to save the value. But, If I run more than 1 date i.e., 1:10 or 1:165 then, I get the error message of "Unable to perform assignment because the size of the left side is 2224060-by-1 and the size of the right side is 1813012-by-1."
clear all
if ispc
filepath1 = ('Z:\ImageDrive\OLI.TIRS\L8\P039\R037');
elseif isunix
filepath1 = ('/home/megh.kc/zdrive/ImageDrive/OLI.TIRS/L8/P039/R037');
end
date1 = dir(filepath1);
date1 ([1 2])= [];
for dates1 =1:161%size(date1,1)
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
  1 Kommentar
Jan
Jan am 4 Okt. 2022
Whenever you mention an error message, care for posting a copy of the complete message. Then the readers can see, where the error occurs.
7321*7351 is 53'816'671. It is unclear, where the dimensions 2'224'060 and 1'813'012 are coming from. Use the debugger to step through the code line by line to find out, where Surface_Reflectance1 gets its size from.
Some hints:
Do not assume, that '.' and '..' are the first two outputs of dir().
date1(ismember({date.name}, {'.', '..'})) = []; % Safer than date1 ([1 2])= []
Avoid repeated work. Store the output of fullfile(filepath1,date1(dates1).name,'L2C2') in a variable.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu File Operations 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!

Translated by