Matlab文件

7 篇文章 0 订阅

xml

H1BCLR110119014219693.L1B.xml

<?xml version="1.0" encoding="UTF-8"?>
<ProductMetaData>
	<ProduceTime>2017-06-28 02:39:01</ProduceTime>
	<End_Center_Longitude>120.3907</End_Center_Longitude>
	<Empty></Empty>
	<TBUS> 19450.000000000    2.040632963   11.000000000 </TBUS>
	<TIR_radiance_and_Tb_Conversion>
		150.0    1.39019    2.35107
		150.1    1.39832    2.36356
		150.2    1.40649    2.37609
		150.3    1.41470    2.38868
	</TIR_radiance_and_Tb_Conversion>
</ProductMetaData>

read_xml.m

% read xml
xmlDoc = xmlread('H1BCLR110119014219693.L1B.xml');

%node
ProductMetaData = xmlDoc.getElementsByTagName('ProductMetaData').item(0);

ProduceTime = char(ProductMetaData.getElementsByTagName('ProduceTime').item(0).getTextContent());
Empty = ProductMetaData.getElementsByTagName('Empty').item(0);

End_Center_Longitude = char(ProductMetaData.getElementsByTagName('End_Center_Longitude').item(0).getTextContent());
End_Center_Longitude = str2double(End_Center_Longitude);

TBUS = char(ProductMetaData.getElementsByTagName('TBUS').item(0).getTextContent());
TBUS = strtrim(TBUS);
TBUS = strsplit(TBUS);
TBUS = str2double(TBUS);

TIR_radiance_and_Tb_Conversion = char(ProductMetaData.getElementsByTagName('TIR_radiance_and_Tb_Conversion').item(0).getTextContent());
TIR_radiance_and_Tb_Conversion = strtrim(TIR_radiance_and_Tb_Conversion);
TIR_radiance_and_Tb_Conversion = strsplit(TIR_radiance_and_Tb_Conversion);
TIR_radiance_and_Tb_Conversion = str2double(TIR_radiance_and_Tb_Conversion);
TIR_radiance_and_Tb_Conversion = reshape(TIR_radiance_and_Tb_Conversion, 3, [])';

文本文件

901834_165.dat

*SoftWare Version 3.0  2018/12/27

*HEADER
     JULIAN DAY	:25854.1424 (days since 1950-01-01 00:00:00 UTC)
*LOCATION
     LATITUDE              :-48.475
     LONGITUDE			:148.619
*FILE
     COLUMN 2	:Corrected Pressure (dbar)	F7.1
     COLUMN 5	:Corrected Temperature (degree_Celsius)	F9.3
=====================================================
    1.1    1.1  1    7.138    7.138  1   34.057   34.057  2
    2.0    2.0  1    7.126    7.126  1   34.057   34.057  2
    3.0    3.0  1    7.127    7.127  1   34.057   34.057  2
    4.0    4.0  1    7.133    7.133  1   34.056   34.056  2
function [status, julian_day, latitude, longitude, temperature] = readArgoDat(file, low_pressure, high_pressure)
%{
file = '1901834_165.dat';
low_pressure = 3;
high_pressure = 4;
[status, julian_day, latitude, longitude, temperature] = readArgoDat(file, ...
low_pressure, high_pressure);
%}
status = false;
julian_day = [];
latitude = [];
longitude = [];
temperature = [];

try
    read_data = false;
    fd = fopen(file);
    line = fgetl(fd);
    while ischar(line)
        line = strtrim(line);
        if read_data
            data_str = strsplit(line) ;
            pressure_str = data_str{2};
            pressure = str2double(pressure_str);
            if pressure>=low_pressure && pressure<=high_pressure
                temperature_str = data_str{5};
                temperature = [temperature str2double(temperature_str)];
            end
            
        end
        if startsWith(line, 'JULIAN')
            str = strsplit(line, ':') ;
            date_str = str{2};
            str = strsplit(date_str) ;
            date_str = str{1};
            julian_day = str2double(date_str) + juliandate(1950, 1, 1, 0, 0, 0);
        elseif startsWith(line, 'LATITUDE')
            str = strsplit(line, ':') ;
            latitude_str = str{2};
            latitude = str2double(latitude_str);
        elseif startsWith(line, 'LONGITUDE')
            str = strsplit(line, ':') ;
            longitude_str = str{2};
            longitude = str2double(longitude_str);
        elseif startsWith(line, '===========')
            read_data = true;
        end
        line = fgetl(fd);
    end
    fclose(fd);
catch
    return;
end

if isempty(temperature)
    return;
end

temperature = mean(temperature);
status = true;

二进制文件

字节运算

LineFlag = bitshift(uint32(allData(i+4)),16) + ...
            bitshift(uint32(allData(i+5)),8) + ...
            uint32(allData(i+6)) ;
LineFlag = typecast(LineFlag, 'int32');


%比特操作
%bitcmp
%bitget(5, 1)

%<<1
bitshift(magic(3), 1)

%0     1     0     1     1     0     0     1     1     1     0     1     0     1     1     0
bitget(bin2dec('0101100111010110'), length(binStr):-1:1)

typecast(uint16(65535),'int16'); %
typecast(swapbytes(uint16(65535)),'int16'); %

读取二进制文件

file='test.bin';
fid=fopen(file,'rb');

headFlag=fread(fid, 3, '*uint8');%3个字节
disp(dec2hex(headFlag));%十六进制显示

cameraFlag=fread(fid, 1, '*uint8');%1个字节
disp(dec2bin(cameraFlag));%二进制显示

lineFlag=fread(fid, 1, '*uint32');%4个字节
lineFlag=swapbytes(lineFlag);%字节交换,大小端

fseek(fid, 260, 'bof');%跳过260个字节

fseek(fid, 0, 'eof');
fsize = ftell(fid);

fclose(fid);

findFiles.m

%{
searchPath=pwd;
fileExt={'.m', '.dat'};
files = findFiles(searchPath, fileExt);
%}

function files = findFiles(searchPath, fileExt)
files = {};
curFiles = dir(searchPath);
for i=1:length(curFiles)
    file = curFiles(i) ;
    name = file.name;
    if isequal(name, '.') || isequal(name, '..')
        continue;
    elseif file.isdir
        dirFiles = findFiles( fullfile(searchPath, name), fileExt );
        for j=1:length(dirFiles)
            files{end+1,1} = dirFiles{j};
        end
    else
        [~,~,ext] = fileparts(name);
        if ( ischar(fileExt) && isequal(fileExt, ext) ) ...
                || ( iscell(fileExt) && any(ismember(fileExt, ext)) )
            files{end+1,1} = fullfile(searchPath, name);
        end
    end
end

pickFiles.m

%从search_path目录搜索满足要求的l1b数据
%(与矩形Northernmost_Latitude,Southernmost_Latitude,Westernmost_Longitude,Easternmost_Longitude有交集)
%并复制到des_path目录
clc;clear;

%搜索路径
%search_path = pwd;
search_path = 'E:\sharing\CentOS7_1611\qt\data\H1C_OPER_OCT_L1B';

%经纬度范围
Northernmost_Latitude = 66.5;
Southernmost_Latitude = 30.2;
Westernmost_Longitude = 110.5;
Easternmost_Longitude = 112.3;

%复制路径
des_path = 'D:\desktop\test\cpp';

%获取搜索路径下的所有h5文件
pattern = '^H1C_OPER_OCT_L1B_\d{8}T\d{6}_\d{8}T\d{6}_\d{5}_\d{2}\.h5$';
files = {};
cur_files = dir(search_path);
for i=1:length(cur_files)
    file = cur_files(i);
    if file.isdir
        continue;
    else
        name = file.name;
        if ~isempty(regexp(name, pattern, 'match'))
            files{end+1,1} = fullfile(search_path, name);
        end
    end
end

for i=1:length(files)
    file = files{i};
    
    %读取文件最边缘经纬度数据
    N_L = h5readatt(file, '/', 'Northernmost Latitude');
    N_L = double(N_L);
    S_L = h5readatt(file, '/', 'Southernmost Latitude');
    S_L = double(S_L);
    W_L = h5readatt(file, '/', 'Westernmost Longitude');
    W_L = double(W_L);
    E_L = h5readatt(file, '/', 'Easternmost Longitude');
    E_L = double(E_L);
    
    %经纬度比较
    if N_L<=Southernmost_Latitude ...
            || S_L>=Northernmost_Latitude ...
            || W_L>=Easternmost_Longitude ...
            || E_L<=Westernmost_Longitude
        continue;
    end
	disp(file);
    copyfile(file, des_path);
end

getFiles.m

function files = getFiles(search_path, pattern)
%{

search_path = 'D:\workspace\matlab\myFile';
pattern='\.m$';
pattern = '^H1[CD]_OPER_OCT_L3A_\d{8}_(CHL|KD9|LW5|MPP|NST|SST|TA8)_[49]KM_\d{2}\.(jpg|h5)$';
files = getFiles(search_path, pattern);

^字符串起始
$字符串结尾
.任意单个字符
.*任意多个字符

expr{m,n} 至少m次,最多n次
expr{m,} 至少m次,没有上限
expr{n} 正好n次
expr? 出现0次或1次
expr* 出现任意次(可以是0次)
expr+ 出现1次或更多次

[abc] 匹配括号里包含的任何单个字符,a或b或c
[^abc] 匹配括号中字符以外的任何单个字符,任何除a和b和c外的字符
[a-x] 匹配a-x范围内的任何单个字符
\s 匹配任何空白字符,等效于[ \f\n\r\t\v]
\S 匹配任何非空白字符,等效于[^ \f\n\r\t\v]
\w 匹配任何字母,数字或下划线字符,对于英文字符集,等效于[a-zA-Z_0-9]
\W 匹配任何除了字母,数字或下划线以外的字符,对于英文字符集,等效于[^a-zA-Z_0-9]
\d 匹配任何数字,等效于[0-9]
\D 匹配任何数字以外的字符,等效于[^0-9]

%}

files = {};
cur_files = dir(search_path);
for i=1:length(cur_files)
    file = cur_files(i);
    name = file.name;
    if isequal(name, '.') || isequal(name, '..')
        continue;
    elseif file.isdir
        dir_files = getFiles(fullfile(search_path, name), pattern);
        for j=1:length(dir_files)
            files{end+1,1} = dir_files{j};
        end
    else
        if ~isempty(regexp(name, pattern))
            files{end+1,1} = fullfile(search_path, name);
        end
    end
end

copyFiles.m

function copyFiles(searchPath, desPath, fileExt)
files = findFiles( searchPath, fileExt );
for i=1:length(files)
    copyfile(files{i}, desPath);
end

readBin.m

function data=readBin(file, varargin)
dataType='float32';
col=1;
if nargin==2
	dataType=varargin{1};
elseif nargin==3
	dataType=varargin{1};
	col=varargin{2};
end
fid = fopen(file, 'r');
data=fread(fid, dataType);
fclose(fid);

row=floor(length(data)/col);
data(col*row+1:end)=[];
data=reshape(data, [col, row])';

%matlab按列,c按行

writeBin.m

function writeBin(file, data)
fid = fopen(file, 'w');
fwrite(fid, data', class(data));
fclose(fid);

%matlab按列,c按行

hdf

readHdfAttr.m

clc;clear;

file='MYD021KM.A2002185.0250.061.2017362175803.hdf';
fileinfo=hdfinfo(file);

%全局属性,Number of Scanss
ind=strcmp({fileinfo.Attributes.Name}, 'Number of Scans');
NumberofScans=fileinfo.Attributes(ind).Value;

%数据名:Data Fields/EV_1KM_RefSB
ind1=find(strcmp({fileinfo.Vgroup.Vgroup(2).SDS.Name},'EV_1KM_RefSB'));
%属性名:reflectance_scales
ind2=find(strcmp({fileinfo.Vgroup.Vgroup(2).SDS(ind1).Attributes.Name},'reflectance_scales'));
EV_1KM_RefSB__reflectance_scales=fileinfo.Vgroup.Vgroup(2).SDS(ind1).Attributes(ind2).Value;

h5

wavelengths=h5readatt(filename, '/products/Lt', 'wavelengths');
Lt=h5read(filename, '/products/Lt');

getSizeStr.m

function str = getSizeStr(bytes)

persistent units;
persistent units_len;
if isempty(units)
    units={'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'};
    units_len=length(units);
end

i=1;
while bytes>=1024 && i<units_len
    bytes = bytes/1024;
    i = i+1;
end

str=sprintf('%.2f%s', bytes, units{i});

tiff

%{
%%批量剪切
pattern='\.tar.gz$';
src_dir='G:\2021.1.20GF\长春及农村';
tar_files=getFiles(fullfile(src_dir, 'tar'), pattern);
for i=1:length(tar_files)
    tar_file=tar_files{i};
    [path_name, base_name, ext] = fileparts(tar_file);
    des_file=fullfile(src_dir, [base_name, ext]);
    if ~isfile(des_file)
        movefile(tar_file, des_file);
    end
end

%%读shape
shape_file='GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684.shp';
shape_file='GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110.shp';
shape_file='GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697.shp';
shape_file='GF6_PMS_E120.0_N30.6_20190807_L1A1119909218.shp';
shape_file='GF5_AHSI_E120.22_N30.82_20190304_004363_L10000036370.shp';
shape_file='GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385.shp';
geoshow(shape_file, 'facecolor',[0 1 0]);
Map = shaperead(shape_file) ;

%%写shape
Map.Geometry = 'Polygon';%元素类型,Point,Line,Polygon等
Map.BoundingBox = [minx,miny;maxx,maxy];
Map.X = [];%坐标X
Map.Y = [];%坐标Y
%保存相关字段,至少需要一个,如果没有其他字段值的话,
%在输出时不会输出dbf文件,导致shp文件不完整,没办法使用.
Map.Id = 1;
Map.Location = '112';
for i=1:5
    Map(i).Geometry = 'Polygon';
    Map(i).BoundingBox = [100*i,100*i;100*i+100,100*i+100];
    Map(i).X = [100*i,100*i+100,100*i+100,100*i,NaN];
    Map(i).Y = [100*i,100*i,100*i+100,100*i+100,NaN];
    Map(i).Id = i;
end
shapewrite(Map, filename); %生成shp,dbf,shx三个文件
%}

%%tiff大小
tiff_files={ 
    'GF1_PMS1_E120.2_N31.6_20200816_L1A0004995322-MSS1.tiff', ...
    'GF1_PMS1_E120.2_N31.6_20200816_L1A0004995322-PAN1.tiff', ...
    'GF1_PMS2_E120.4_N31.3_20180503_L1A0003160130-MSS2.tiff', ...
    'GF1_PMS2_E120.4_N31.3_20180503_L1A0003160130-PAN2.tiff', ...
    'GF1_WFV1_E101.1_N25.2_20140412_L1A0000202014.tiff', ...
    'GF1_WFV2_E120.0_N31.0_20190523_L1A0004017288.tiff', ...
    'GF1_WFV3_E119.2_N32.3_20190503_L1A0003975764.tiff', ...
    'GF1_WFV4_E120.1_N31.9_20180720_L1A0003337583.tiff', ...
    'GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684-MUX.tiff', ...
    'GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684-MUX1.tiff', ...
    'GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684-MUX2.tiff', ...
    'GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684-PAN.tiff', ...
    'GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684-PAN1.tiff', ...
    'GF1B_PMS_E119.9_N30.8_20180928_L1A1227529684-PAN2.tiff', ...
    'GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110-MUX.tiff', ...
    'GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110-MUX1.tiff', ...
    'GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110-MUX2.tiff', ...
    'GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110-PAN.tiff', ...
    'GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110-PAN1.tiff', ...
    'GF1C_PMS_E119.9_N30.8_20190725_L1A1021447110-PAN2.tiff', ...
    'GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697-MUX.tiff', ...
    'GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697-MUX1.tiff', ...
    'GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697-MUX2.tiff', ...
    'GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697-PAN.tiff', ...
    'GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697-PAN1.tiff', ...
    'GF1D_PMS_E120.3_N30.8_20180719_L1A1240541697-PAN2.tiff', ...
    'GF2_PMS1_E120.1_N31.5_20190830_L1A0004214760-MSS1.tiff', ...
    'GF2_PMS1_E120.1_N31.5_20190830_L1A0004214760-PAN1.tiff', ...
    'GF2_PMS2_E120.4_N31.5_20190830_L1A0004223897-MSS2.tiff', ...
    'GF2_PMS2_E120.4_N31.5_20190830_L1A0004223897-PAN2.tiff', ...
    'GF4_PMS_E118.8_N32.0_20180718_L1A0000203483.tiff', ...
    'GF5_AHSI_E120.22_N30.82_20190304_004363_L10000036370_OGP.tiff', ...
    'GF5_AHSI_E120.22_N30.82_20190304_004363_L10000036370_SW.geotiff', ...
    'GF5_AHSI_E120.22_N30.82_20190304_004363_L10000036370_VN.geotiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_40mOGP.tiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_B7.tiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_B8.tiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_B9.tiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_B10.tiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_B11.tiff', ...
    'GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_B12.tiff', ...
    'GF6_PMS_E120.0_N30.6_20190807_L1A1119909218-MUX.tiff', ...
    'GF6_PMS_E120.0_N30.6_20190807_L1A1119909218-PAN.tiff', ...
    'GF6_WFV_E118.7_N31.4_20200512_L1A1119996632-1.tiff', ...
    'GF6_WFV_E118.7_N31.4_20200512_L1A1119996632-2.tiff', ...
    'GF6_WFV_E118.7_N31.4_20200512_L1A1119996632-3.tiff'};

for i=1:length(tiff_files)
    tiff_file=tiff_files{i};
    info=imfinfo(tiff_file);
    width=info.Width;
    height=info.Height;
    fprintf(1, 'file:%s, width:%d, height:%d\n', tiff_file, width, height);
    bitDepth=info.BitDepth;
    band_num=length(info.BitsPerSample);
    fprintf(1, '\tBitDepth:%d, band_num:%d, dataSize:%s\n\n', ...
        bitDepth, band_num, getSizeStr(width*height*bitDepth/8));
    
    data=imread(tiff_file);
    
    %gray
    %{
    if size(data, 3) ~= 1
        data = data(:, :, 1);
    end
    [height, width]=size(data);
    if height>4000
        height=round(height/2)-2000:round(height/2)+2000;
    else
        height=1:height;
    end
    if width>6000
        width=round(width/2)-3000:round(width/2)+3000;
    else
        width=1:width;
    end
    data=data(height, width);
    grey = histogramEqualization(data);
    grey = reshape(grey, size(data));
    rgb = cat(3, grey, grey, grey);
    rgb = uint8(round(rgb*255));
    [~, name]=fileparts(tiff_file);
    imwrite(rgb, [name, '_grey.png']);
    %}
    
    %rgb
    if size(data, 3) < 3
       continue;
    end
    
    height=size(data, 1);
    width=size(data, 2);
    
    if height>4000
        height=round(height/2)-2000:round(height/2)+2000;
    else
        height=1:height;
    end
    if width>6000
        width=round(width/2)-3000:round(width/2)+3000;
    else
        width=1:width;
    end
    data=data(height, width, 1:3);
    
    height=size(data, 1);
    width=size(data, 2);
    
    r = data(:, :, 1);
    r = histogramEqualization(r);
    r = reshape(r, [height, width]);
    
    g = data(:, :, 2);
    g = histogramEqualization(g);
    g = reshape(g, [height, width]);
    
    b = data(:, :, 3);
    b = histogramEqualization(b);
    b = reshape(b, [height, width]);
    
    rgb = cat(3, r, g, b);
    rgb = uint8(round(rgb*255));
    [~, name]=fileparts(tiff_file);
    imwrite(rgb, [name, '_rgb.png']);
    
end

%%读tiff
tiff_path='D:\project\data';
pattern='\.tiff$';
pattern='\.geotiff$';
tiff_files = getFiles(tiff_path, pattern);
pick_j=2;
for i=1:length(tiff_files)
    tiff_file=tiff_files{i};
    info=imfinfo(tiff_file);
    sample=length(info.BitsPerSample);
    width=info.Width;
    height=info.Height;
    fprintf(1, '%s\n', tiff_file);
    fprintf(1, '\tsmaple:%d\n', sample);
    fprintf(1, '\twidth:%d\n', width);
    fprintf(1, '\theight:%d\n', height);
    
    data=imread(tiff_file);
    if sample==1
        for j=1:10
            fprintf(1, '\tdata[%d]:%d\n', j, data(1, j));
        end
    else
        for j=1:10
            fprintf(1, '\tdata[%d]:%d\n', j, data(1, j, pick_j));
        end
    end
    pause;
end

tiff_file='D:\project\data\GF5\GF5_AHSI_E120.22_N30.82_20190304_004363_L10000036370_OGP.tiff';
tiff_file='D:\project\data\GF5\GF5_VIMS_N31.3_E120.1_20191101_007897_L10000240385_40mOGP.tiff';
data=imread(tiff_file);

tmp=data(:, :, 1);

tiff.m

path='E:\workSpace\vs2017\QtGF5_2.0\QtGF5\';
%输入实例影像路径
file='cdom_algorithm1.tif';
file='xuanfuwu_algorithm1.tif';
file='xuanfuwu_algorithm2.tif';
file='xuanfuwu_algorithm3.tif';

file='yelvsu_algorithm1.tif';
file='yelvsu_algorithm2.tif';
file='yelvsu_algorithm3.tif';

%读取影像信息
[Imgae_Data, geo]=geotiffread([path,file]);
Imgae_Data=double(Imgae_Data);

%读取投影信息
info=geotiffinfo([path,file]);

%将产品保存为TIFF
%geotiffwrite(Out_path,CDOM_array,geo,'GeoKeyDirectoryTag',info.GeoTIFFTags.GeoKeyDirectoryTag)

获取指定目录下所有文件

fileFolder='D:\project\hy1\浮标数据\201903';
dirOutput=dir(fullfile(fileFolder, '*.dat'));
fileNames={dirOutput.name};

number = length(fileNames);
for i=1:number
	file = fullfile(fileFolder, fileNames{i});
	disp(file);
end

获取指定目录及其子目录下所有文件

function files = getFiles(search_path, pattern)
%{

search_path = 'D:\workspace\matlab\myFile';
pattern='\.m$';
files = getFiles(search_path, pattern);

^字符串起始
$字符串结尾
.任意单个字符
.*任意多个字符

expr{m,n} 至少m次,最多n次
expr{m,} 至少m次,没有上限
expr{n} 正好n次
expr? 出现0次或1次
expr* 出现任意次(可以是0次)
expr+ 出现1次或更多次

[abc] 匹配括号里包含的任何单个字符,a或b或c
[^abc] 匹配括号中字符以外的任何单个字符,任何除a和b和c外的字符
[a-x] 匹配a-x范围内的任何单个字符
\s 匹配任何空白字符,等效于[ \f\n\r\t\v]
\S 匹配任何非空白字符,等效于[^ \f\n\r\t\v]
\w 匹配任何字母,数字或下划线字符,对于英文字符集,等效于[a-zA-Z_0-9]
\W 匹配任何除了字母,数字或下划线以外的字符,对于英文字符集,等效于[^a-zA-Z_0-9]
\d 匹配任何数字,等效于[0-9]
\D 匹配任何数字以外的字符,等效于[^0-9]

%}

files = {};
cur_files = dir(search_path);
for i=1:length(cur_files)
    file = cur_files(i);
    name = file.name;
    if isequal(name, '.') || isequal(name, '..')
        continue;
    elseif file.isdir
        dir_files = getFiles(fullfile(search_path, name), pattern);
        for j=1:length(dir_files)
            files{end+1,1} = dir_files{j};
        end
    else
        if ~isempty(regexp(name, pattern))
            files{end+1,1} = fullfile(search_path, name);
        end
    end
end

文本文件提取下载链接

clear all;
file='url_source.txt';
lines=textread(file, '%s', 'delimiter', '\n');

pat='A\d{13}.L2_LAC_OC\.nc';
data={};
for i=1:length(lines)
    temp=lines{i};
    temp=regexpi(temp, pat, 'match');
    if ~isempty(temp)
    	for j=1:length(temp)
        	data0{end+1}=temp{j};
        end
    end
end
data=unique(sort(data));

fid=fopen('Alink201709.txt','w');
for i=1:length(data)
    fprintf(fid,'https://oceandata.sci.gsfc.nasa.gov/ob/getfile/%s\n', data{i});
end
fclose(fid);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值