私がファイルを持っているとしましょう:
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