Saturday, July 18, 2020

Code:多项参考

  1. [Matlab]删除XLS文件特定Sheet或空白Sheet(默认Sheet);
  2. [SPEI_SPI]计算栅格站点;
  3. [Matlab]统计知网关键词词频;
  4. [Matlab]
  5. 1
    2
    3
    4
    5
    % Read Image
    [image, geo]=readgeoraster(imgpath);
    info=georasterinfo(imgpath);
    % Save Image
    geotiffwrite('newimg.tif', image, geo); 
    
    % read a geo-referenced image 
    [image, geo]=readgeoraster(filepath);
    
    try
        info=geotiffinfo(filepath);
    catch
        info=georasterinfo(filepath);
    end
    
    % write a geo-referenced image 
    try
        geotiffwrite(otpath, uint8(class_imag), geo);
    catch
        strcmd=['gdalinfo ', filepath];
        [~, cmdout]=system(strcmd);
        epsg=extractBetween(cmdout, "EPSG:"," got from GeoTIFF keys");
        epsg=epsg{1};
        % geotiffwrite(otpath, uint8(class_imag), geo, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
        geotiffwrite(otpath, uint8(class_imag), geo, 'CoordRefSysCode', ['EPSG:', epsg]);
    end
    
    1
    geotiffwrite(otpath, uint8(class_imag), geo, 'CoordRefSysCode', ['EPSG:', epsg], 'TiffType', 'bigtiff');
    
    1
    geotiffwrite('m2.tif', image, geo, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
    
  6. [Matlab] A powerful toolbox for exporting images, refer to the online documentation for usage instructions; to save images and prevent accidents, use export_fig('exportfig_painters.png', '-png', '-painters', '-r300');. When the image contains Chinese characters, refer to this code snippet: export_fig([name,'.png'], '-png', '-r400','-q300');.
  7. [Matlab] Get the parent folder path
  8.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    %==========================================================================================================================
    % Gets the folder one level up.  If startingFolder is a filename with an extension it gets the containing folder and the child folder is null.
    % Returns null for both if the folder does not exist, and it's not a filename either.
    function [parentFolder, childFolder] = GetParentFolder(startingFolder)
    parentFolder = []; % Initialize
    childFolder = []; 
    try
    	if isfolder(startingFolder)
    		[parentFolder, childFolder, ext] = fileparts(startingFolder);
    		% Need to append extension for rare cases where deepest folder has a dot in the name.
    		childFolder = [childFolder, ext];
    	elseif isfile(startingFolder)
    		% It's a filename, not a folder.  Need to change otherwise childFolder will be returned as the base file name.
    		[parentFolder, childFolder, ext] = fileparts(startingFolder);
    		childFolder = []; % No child folder since it's a filename, not a folder name.
    	end
    catch ME
    	message = sprintf('Error in GetParentFolder():\n%s', ME.message);
    	uiwait(msgbox(message));
    end
    return; % from GetParentFolder
    end
    
  9. [Matlab]Export text on a text file.
  10. 1
    2
    3
    4
    fid=fopen(txtpath, 'w', 'n', 'US-ASCII');
    fprintf(fid, '%s\r\n', num2str(value));
    fclose(fid);
    fclose('all');
    
  11. [Matlab]Enhance RGB Image Code.
  12.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    function enhan_image=GenenhanImage(filepath)
    %  https://www.mathworks.com/matlabcentral/fileexchange/64932-files-for-demystifying-deep-learning-semantic-segmentation-and-deployment?s_tid=srchtitle
         % Load the images located in the above path using imageDatstore - ML Function
        imds = imageDatastore(filepath);
        pic_num = 1;
        I_raw = readimage(imds, pic_num);
    
        enhan_image= histeq(uint8(I_raw)); 
    
    end
    

Tuesday, May 26, 2020

Matlab:经纬坐标生成ArcGIS点文件

此程序目前只适用于经纬坐标,如为其他投影请更换blank.shp及pre.prj文件(互为一体)。Files

Friday, January 24, 2020

TeX:中文支持工具

CTeX套装

CTeX套装是科学院吴凌云研究员的个人作品。在CTeX套装刚刚问世之时,因其解决了繁琐的中文字体安装工作,所以广受欢迎。但是,一方面CTeX套装已经很久不更新,内里的宏包、工具陈旧;另一方面,随着XeLaTeX的发展,以及xeCJK等技术的成熟,上述这些繁琐的工作已经没有必要而失去意义;因此,现在不推荐使用 CTeX套装。

CTeX宏集

CTeX宏集和CTeX套装是两个不同的东西。
CTeX宏集是集成了中文支持、操作系统判定、字体选择、版式预设为一体的一组宏包和文档类的合集。我们推荐在任何情况下,优先使用CTeX宏集处理中文。

TeX Live

TeX Live是TUG (TeX User Group)维护和发布的TeX系统,可说是「官方」的TeX系统。我们推荐任何阶段的TeX用户,都尽可能使用TeX Live,以保持在跨操作系统平台、跨用户的一致性。TeX Live的官方站点是https://tug.org/texlive/。
国内下载站点请见参考文献[1]。

安装过程

Windows用户右键单击install-tl-advanced.bat,以管理员权限执行;除了安装位置,所有选项都应保留默认。
安装结束后,可以在CMD窗口键入简单命令,无返回错误即为安装成功。
Fig. 1
TeXworks editor是TeX Live自有编辑器,打开它。在里面,键入一段含有中文的完整TeX代码,如下:
\documentclass[UTF8]{ctexart}
\begin{document}
\section{文字}
测试部分!
\section{数学}
\[
  a ^2+ b^2=c^2
\]

这是数学公式!
\end{document}
运行后,得到如下图即为安装成功。
Fig. 2
TeXworks editor操作说明见参考文献[3]。

参考文献

[2] The TEX Live Guide—2019. 各种文本教程(含中文)在2.2.