Wednesday, May 10, 2017

IDL: 关闭所有文件

代码示例:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
;; get all files IDs
fids = envi_get_file_ids()
size = size(fids)
length = size[1]

for j = 0L, length-1, 1 do begin
      ;; to delete the specified file from the hard disk
      ENVI_FILE_MNG, id = fids[j], /DELETE
      ;; to remove the specified file from within ENVI Classic
      ;;ENVI_FILE_MNG, id = fids[j], /REMOVE
endfor

Thursday, April 27, 2017

GOLang: 搭建GO语言IDE

GO的IDE组件包含2部分:

Binary distribution

首先,搭建工作在参考文献[1]下载适用于不同平台的Binary distribution。目标机器是Win7 64bit,所以下载go1.8.1.windows-amd64.msi安装程序。
双击启动安装,本例的安装位置位于C:\Tools\GO,安装结束后须在环境变量Path添加启动位置如C:\Tools\GO\bin,这部分就安装好了。

Liteide

其次,搭建工作在参考文献[2]下载适用于不同平台的安装程序。对应于目标机器,这里下载liteidex31.windows-qt4.zip。下载结束后解压,本程序不需要安装,直接将它放置在一定位置即可。
在~\liteide\bin下,找到liteide.exe并为其创建快捷方式,我将快捷方式置于桌面,方便随时启动该IDE。
检验搭建是否成功只需运行一小段代码即可,请见参考文献[3]。
IDE部分属性配置请见参考文献[4]。

References

Tuesday, April 11, 2017

FFmpeg: Clip Audio Files

Introduction

剪辑音频文件,提取出文件特定时间的音频资料,并且周而复始。
文献[1]示例代码:
1
ffmpeg -ss 0 -t 30 -i file.mp3 file.wav
代码
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
% Created by LI Xu
% Version 1.0
% April 11, 2017

% Description:
% 

% If you have any question about this code,
% please do not hesitate to contact me via E-mail: 
% jeremy456@163.com

% Blog:
% http://blog.sciencenet.cn/u/lixujeremy
% http://lixuworld.blogspot.com/

% Reference
% http://stackoverflow.com/questions/7945747/how-can-you-only-extract-30-seconds-of-audio-using-ffmpeg

clear;
clc;

timebegin=tic;
cur_data=date;
cur_time=fix(clock);
str1=sprintf('%s %.2d:%.2d:%.2d', cur_data, cur_time(4), cur_time(5), cur_time(6)); 
fprintf('Time Begin: ');
fprintf(str1);
fprintf('\n');

% XLS
xlspath='AudioInfo.xlsx';
[~, conaud]=xlsread(xlspath);
conaud(1, :)=[];

% Source Directory
SouDir='input';
% Destination Directory
DesDir='output';

% Loop
for ii=1:size(conaud, 1)
    rowrd=conaud(ii, :);
    filepath=GetFilePath(SouDir, rowrd{1});
    if filepath==0
        continue;
    end
    [~, filename, ext]=fileparts(filepath);
    inpath=fullfile(SouDir, [filename, ext]);
    otpath=fullfile(DesDir, [filename, ext]);
    if exist(otpath, 'file')
        delete(otpath);
    end
    % Start
    sttm=rowrd{2};
    % Finish
    fitm=rowrd{3};
    % Construct Sentence
    Constr=['ffmpeg -ss ', sttm, ' -t ', fitm, ' -i ', inpath, ' ', otpath];
    disp(['...Start to process ', filename, ext, '...']);
    [stuat, cmdout]=system(Constr);
    disp(['...Finish ', filename, ext, '...']);

end

fprintf('Time Begin: ');
fprintf(str1);
fprintf('\n');

cur_data=date;
cur_time=fix(clock);
str2=sprintf('%s %.2d:%.2d:%.2d', cur_data, cur_time(4), cur_time(5), cur_time(6)); 
fprintf('Time End: ');
disp(str2);
timespan=toc(timebegin);
fprintf('Time Span: %.4f s\n', timespan);

disp('******************************************');

References

Wednesday, February 8, 2017

Tool: CMD执行简单EXE

Introduction

Win系统启动CMD,将CMD当前目录导航至EXE所在文件夹,而后在命令行中键入EXE文件名称,回车执行。执行成功输出一行文字“This is a simple C++ program!”,如Fig. 1。
Fig. 1
或者,在不切换目录的前提下,将EXE文件绝对路径键入命令行执行亦可。

References

Thursday, January 12, 2017

Math: 敏感度系数

Introduction

敏感度系数,又称灵敏度,表示项目评价指标对不确定因素的敏感程度。
计算公式:
\[E = \frac{{\Delta A}}{{\Delta F}}\]
式中,E为评价指标A对于不确定因素F的敏感度系数;
ΔA为不确定因素F发生ΔF变化率时,评价指标A的相应变化率,%;
ΔF为不确定因素F的变化率,%。

对于博士论文

情景情节设置变化率(r)使用在斜率因子(a),ΔF计算如下:
\[\begin{array}{c} \Delta F = \frac{{{I_{{\rm{changed}}}} - {I_{{\rm{no\_changed}}}}}}{{{I_{{\rm{no\_changed}}}}}}\\ = \frac{{a\left( {1 + r} \right)x + b - \left( {ax + b} \right)}}{{ax + b}}\\ = \frac{{ax + arx + b - ax - b}}{{ax + b}}\\ = \frac{{arx}}{{ax + b}} \end{array}\]

References

[1] 娄伟. 情景分析理论与方法[M]. 北京: 社会科学文献出版社, 2012, pp: 246~247.

Office: 表格文字上下左右居中

Introduction

表格文字在选择“单元格对齐方式”——居中之后,依然表现不好,怎么调整都不能得到满意的结果,如Fig. 1所示。
Fig. 1
这种情况很可能是单元格文字的“段落”——行间距配置不当,选中全部表格单元格文字,找到“段落”属性,如Fig. 2,配置行距为“单倍行距”。
Fig. 2
调整之后,就得到满意的结果,Fig. 3。
Fig. 3