假设我有文件:
famcal.2012000000000000000000625502.stellar.blu
famcal.2012000000000000000000625502.stellar.grn
famcal.2012000000000000000000625502.stellar.red
famcal.2012000000000000000000625502.stellar.nir
famcal.2012000000000000000000625503.stellar.blu
famcal.2012000000000000000000625503.stellar.grn
famcal.2012000000000000000000625503.stellar.red
famcal.2012000000000000000000625503.stellar.nir
famcal.2012000000000000000000625504.stellar.blu
famcal.2012000000000000000000625504.stellar.grn
famcal.2012000000000000000000625504.stellar.red
famcal.2012000000000000000000625504.stellar.nir
famcal.2012000000000000000000625505.stellar.blu
famcal.2012000000000000000000625505.stellar.grn
famcal.2012000000000000000000625505.stellar.red
famcal.2012000000000000000000625505.stellar.nir
famcal.2012000000000000000000625506.stellar.blu
famcal.2012000000000000000000625506.stellar.grn
famcal.2012000000000000000000625506.stellar.red
famcal.2012000000000000000000625506.stellar.nir
famcal.2012000000000000000000625507.stellar.blu
famcal.2012000000000000000000625507.stellar.grn
famcal.2012000000000000000000625507.stellar.red
famcal.2012000000000000000000625507.stellar.nir
我希望能够按此顺序使用所有这些文件,以生成一个新矩阵。
所以本质上,一段代码可以通过以下顺序:
625502
625503
625504
625505
625506
625507
并且对于这些数字集合中的每一个,请执行以下顺序:
blu
grn
red
nir
我目前正在使用从每个文件中提取小矩阵的代码,然后将它们保存到新矩阵中的新位置。例如:
a = 2000;
star_block = repmat(a,[41,78]); %populates matrix with 2000
这将创建一个填充 2000 的矩阵。我想用上面文件的输出替换这个矩阵的某些部分。
star_block(2:10,4:12) = 625502 blu
star_block(12:20,4:12) = 625502 grn
star_block(22:30,4:12) = 625502 red
star_block(32:40,4:12) = 625502 nir
star_block(2:10,17:25) = 625503 blu
star_block(12:20,17:25) = 625503 grn
star_block(22:30,17:25) = 625503 red
star_block(32:40,17:25) = 625503 nir
star_block(2:10,30:38) = 625504 blu
star_block(12:20,30:38) = 625504 grn
star_block(22:30,30:38) = 625504 red
star_block(32:40,30:38) = 625504 nir
star_block(2:10,43:51) = 625505 blu
star_block(12:20,43:51) = 625505 grn
star_block(22:30,43:51) = 625505 red
star_block(32:40,43:51) = 625505 nir
star_block(2:10,56:64) = 625506 blu
star_block(12:20,56:64) = 625506 grn
star_block(22:30,56:64) = 625506 red
star_block(32:40,56:64) = 625506 nir
star_block(2:10,69:77) = 625507 blu
star_block(12:20,69:77) = 625507 grn
star_block(22:30,69:77) = 625507 red
star_block(32:40,69:77) = 625507 nir
编辑:
band_files = dir([star_path '/*.blu']);
for i=1:length(band_files)
blue01 = band_files(1).name;
green01 = strrep(blue01, 'blu', 'grn');
red01 = strrep(blue01, 'blu', 'red');
nir01 = strrep(blue01, 'blu', 'nir');
blue02 = band_files(2).name;
green02 = strrep(blue02, 'blu', 'grn');
red02 = strrep(blue02, 'blu', 'red');
nir02 = strrep(blue02, 'blu', 'nir');
blue03 = band_files(3).name;
green03 = strrep(blue03, 'blu', 'grn');
red03 = strrep(blue03, 'blu', 'red');
nir03 = strrep(blue03, 'blu', 'nir');
blue04 = band_files(4).name;
green04 = strrep(blue04, 'blu', 'grn');
red04 = strrep(blue04, 'blu', 'red');
nir04 = strrep(blue04, 'blu', 'nir');
blue05 = band_files(5).name;
green05 = strrep(blue05, 'blu', 'grn');
red05 = strrep(blue05, 'blu', 'red');
nir05 = strrep(blue05, 'blu', 'nir');
blue06 = band_files(6).name;
green06 = strrep(blue06, 'blu', 'grn');
red06 = strrep(blue06, 'blu', 'red');
nir06 = strrep(blue06, 'blu', 'nir');
end
blue1 = [star_path '\' blue01];
green1 = [star_path '\' green01];
nir1 = [star_path '\' nir01];
red1 = [star_path '\' red01];
%blue
fid=fopen(blue1,'rb'); % opens the file for reading
fseek (fid, 800, -1);% Skip past header, which is 800 bytes long
blue = fread(fid, [3552,6536], '*uint16', 'ieee-be');%reads in and converts .RAS file
blue_chip = extract_region_fwd(blue);
star_block(2:10,4:12) = blue_chip;%inserts star chip into main matrix
%green
fid=fopen(green1,'rb'); % opens the file for reading
fseek (fid, 800, -1);% Skip past header, which is 800 bytes long
green = fread(fid, [3552,6536], '*uint16', 'ieee-be');%reads in and converts .RAS file
green_chip = extract_region_fwd(green);
star_block(12:20,4:12) = green_chip;%inserts star chip into main matrix
%red
fid=fopen(red1,'rb'); % opens the file for reading
fseek (fid, 800, -1);% Skip past header, which is 800 bytes long
red = fread(fid, [3552,6536], '*uint16', 'ieee-be');%reads in and converts .RAS file
red_chip = extract_region_fwd(red);
star_block(22:30,4:12) = red_chip;%inserts star chip into main matrix
%nir
fid=fopen(nir1,'rb'); % opens the file for reading
fseek (fid, 800, -1);% Skip past header, which is 800 bytes long
nir = fread(fid, [3552,6536], '*uint16', 'ieee-be');%reads in and converts .RAS file
nir_chip = extract_region_fwd(nir);
star_block(32:40,4:12) = nir_chip;%inserts star chip into main matrix