Thursday, June 27, 2013

Debian change default display manager and session

To change default display manager
$  sudo nano /etc/X11/default-display-manager

To change default session
$ update-alternatives --config x-session-manager
Read more ...

Wednesday, June 26, 2013

Linux command for username and group

Change or rename user name and UID (user-id)
# usermod -l <new_username> <old_username>
# usermod -u UID <username>

List username from a group
# getent group <groupname>

Remove username from a group
# gpasswd -d <username> <group>

Remove/Delete a user account
# userdel <username>
The following command will also remove user home directory
# userdel -r <username>

Add user to a group
# adduser <username> <group>
Read more ...

Control Volume with Keyboard Shortcut in Xfce

Add an Xfce shortcut by going to Applications > Settings > Keyboard.

Code for volume up/down/mute

amixer set Master 3%+
amixer set Master 3%-
amixer set Master toggle


Read more ...

Friday, June 21, 2013

Ubuntu/Debian 下安装 VirtualBox 虚拟 Win7

官方网站:http://www.virtualbox.org/

VirtualBox中虚拟Win7
运行Vbox
–》单击左上角New,新建虚拟环境。
–》填写名称和将要虚拟的操作系统版本。
–》然后是内存设置,默认即可,如果host主机内存够大,可以多设。
–》接下来虚拟硬盘,一路默认即可,最后确认,完成。

安装Win7
–》准备好系统镜像。win7.iso。
–》单击左上角Settings,会提示:Failed to access the USB subsystem.VirtualBox is not currently allowed to access USB devices. You can change this by adding your user to the ‘vboxusers’ group. Please see the user manual for a more detailed explanation.
将用户名添加到vboxusers组,重启或注销后即可解决。
sudo adduser usrname vboxusers
–》选择Storage,在看到IDE controler控制器下有硬盘和光盘, 光盘显示Empty,点击右侧Attributes属性中CD/DVD drive 右边的光盘图像,Set up the virtual CD/DVD drive,选择硬盘上下载的iso镜像文件,创建虚拟光驱。如果下面的步骤无法继续,在这里还可以尝试添加Sata 控制器。
–》设置好Storage点击Start 开始。接下来和普通安装Win7一样了。
–》安装完。优化设置,重新安装有问题的主板驱动;配置网络:如果无法上网,Settings中设置network从AMD换为intel(r) PR0/1000 MT Network Connection等,启动网卡驱动安装。

设置共享文件
Guest(win)
–》在Settings – Share Folders 点击+号新建共享文件夹,可选择Auto Mount 自动挂载。
–》点击顶部菜单设备device选项–Install Guest Additions,进行安装。
安装完毕,即可看到共享文件夹。

Guest(linux)

For linux guest, You may have to install following packages to complete Guest additions.

To dispaly the KERNELVERSION of the running distribution, you can use
uname -r

sudo apt-get install xserver-xorg xserver-xorg-core build-essential linux-headers-KERNELVERSION dkms
  1. sudo mkdir /media/shared  
  2. sudo mount.vboxsf Share /media/shared  
  3. sudo gedit /etc/fstab  
add the following into fstab:
Share /media/shared vboxsf rw 0 0
Share 为你要共享的文件夹 可以在settings里面设置。


支持USB
VirtualBox启用USB 2.0 必须安装:Oracle VM VirtualBox Extension Pack for Windows。在窗口顶部菜单File-Preferance-Extensions中添加下载的extpack。最后在Settings的usb选项中启用USB2.0,然后添加usb设备,即可。

摄像头驱动
同样在USB设置中添加摄像头。然后到虚拟的Win7里面安装相应驱动即可。
 
Read more ...

MATLAB FUNCTION accumarray

A = accumarray(subs,val,sz,fun,fillval)
  sub:提供累计信息的指示向量
   val:提供累计数值的向量
    sz:控制输出向量A的size
   fun:用于计算累计后向量的函数,默认为@sum,即累加
fillval:填补A中的空缺项,默认为0


例子:

  1. myfun = @(x) 1./(2*numel(x)) * sum(x);  

myfun = 

    @(x)1./(2*numel(x))*sum(x)

  1. subs=[7,2,5,7,2]';  

subs =

     7
     2
     5
     7
     2

  1. val=1:5;  

val =

     1     2     3     4     5

  1. sz=[10,1];  

sz =

    10     1

  1. A=accumarray(subs,val,sz,myfun,nan);  

A =

       NaN
    1.7500
       NaN
       NaN
    1.5000
       NaN
    1.2500
       NaN
       NaN
       NaN

个人对此函数的理解:
首先,函数根据参数中sz,生成一个中间矩阵B,此例中sz=[10,1],所以B是一个10*1的矩阵。
然后,函数根据subs中的指示,将val中的数值摆放到B中。
  subs  val
     7     1
     2     2
     5     3
     7     4
     2     5
意思就是,val中的1被扔到了B中第7的位置,同样,2扔到B中第2个位置,3到B中5,4到B中7,5到2。
这样B中的2,5,7位就被摆放上了数值,而且,2和7两个位置上被摆上了2个数值。

B =

   NaN
   2,5
   NaN
   NaN
   3
   NaN
   1,4
   NaN
   NaN
   NaN
其他还有7个位置并没有被摆放任何数值,我们暂时不管他,给他扔上NaN。
然后,accumarray函数就会根据自定义的函数myfun,来计算了。拿什么算呢,拿的就是这个中间矩阵B,我们定义的myfun意义就是均值的一般,所以也可以定义的时候写成:

  1. myfun = @(x) mean(x)./2;  

这下就简单了,就相当于mean(B)./2,然后得出的结果就是A了。
A =

       NaN
    1.7500
       NaN
       NaN
    1.5000
       NaN
    1.2500
       NaN
       NaN
       NaN
个人理解大概是个这样的过程,接下来再去看matlab的help文件就比较容易懂了。
Read more ...

MATLAB中的共轭转置与非共轭转置

对已知矩阵A,MATLAB为我们提供了两种转置运算。
A.' 非共轭转置

A' 共轭转置

单纯地共轭用:conj()
非共轭可以用:transpose()

example:
  a =
        12.0000                  0 + 2.0000i         5.0000         
        0                             5.0000               4.0000 
>> a'
             ans =
                      12.0000                  0         
                      0 - 2.0000i              5.0000         
                      5.0000                    4.0000         
>> a.'
           ans =

                   12.0000                  0         
                  0 + 2.0000i              5.0000         
                  5.0000                    4.0000

Read more ...

决定系数和残差

首先看看几个定义:
总体平方和TSS( total sum of squares)
回归平方和RSS(regression sum of squares)
残差平方和ESS(Residual sum of squares)
其中yi表示实验数据,fi 表示模拟值,表示样本平均值。
决定系数(Coefficient of determination)

在一定程度上反应了模型的拟合优度。
其实就是回归平方和在总体平方和中所占的比例。因为TSS=RSS+ESS
The better the linear regression (on the right) fits the data in comparison to the simple average (on the left graph), the closer the value of R2 is to one. The areas of the blue squares represent the squared residuals with respect to the linear regression. The areas of the red squares represent the squared residuals with respect to the average value.
红色区域是总体平方和,蓝色为残差平方和。
>> 为什么要用决定系数去反应拟合优度,而不用残差平方和呢?
>> 因为,残差平方和与观测值的绝对大小有关,而决定系数是一个比例。
比如:有一组数据:1000,2000,35000...
            另一组数据:1,2,3.5...
这个时候就会发现第一组数据的拟合后残差平方和会大很多,但是不见得,模型拟合优度就会差。
Read more ...

Latex(Emacs+Auctex+Jabref)中参考文献处理

>> 文献管理用 Jabref,可以很方便的管理文献,其 BibTeX 文献数据库可供 Latex 或其他软件使用,可与 emacs,vim,kile 等多种软件结合使用。所有文献信息都被记录在bib文件中。格式如下(myref.bib)。

  1. @ARTICLE{Journel1994,  
  2.   author = {Journel, André and Xu, Wenlong},  
  3.   title = {Posterior identification of histograms conditional to local data},  
  4.   journal = {Mathematical Geology},  
  5.   year = {1994},  
  6.   volume = {26},  
  7.   pages = {323-359},  
  8.   note = {10.1007/BF02089228},  
  9.   __markedentry = {[mao]},  
  10.   abstract = {Stochastic simulation techniques which do not depend on a back transform  
  11.     step to reproduce a prior marginal cumulative distribution function  
  12.     (cdf) may lead to deviations from that distribution which are deemed  
  13.     unacceptable. This paper presents an algorithm to post process simulated  
  14.     realizations or any spatial distribution to reproduce the target  
  15.     cdf in the case of continuous variables or target proportions in  
  16.     the case of categorical variables, yet honoring the conditioning  
  17.     data. Validations conducted for both continuous and categorical cases  
  18.     show that. by adjusting the value of a correction level parameter  
  19.     , the target cdf or proportions can be well reproduced without significant  
  20.     modification of the spatial correlation patterns of the original  
  21.     simulated realizations .},  
  22.   affiliation = {Stanford University Geological and Environmental Sciences Department  
  23.     94305 Stanford California},  
  24.   issn = {0882-8121},  
  25.   issue = {3},  
  26.   keyword = {Earth and Environmental Science},  
  27.   owner = {mao},  
  28.   publisher = {Springer Netherlands},  
  29.   timestamp = {2011.10.13},  
  30.   url = {http://dx.doi.org/10.1007/BF02089228}  
  31. }  

>> 用 Emacs+Auctex 写文章时参考文献的引用方法:
首先将 bib 文件放到 tex 同一目录下,在 tex 文档中加入

  1. \bibliographystyle{ieeetr}  
  2. \bibliography{myref}  

这里,bibliographystyle 有很多种,可以查看 /usr/share/texmf-texlive/bibtex/bst/base 里面的bst文件。接下来我们就可以用 \cite{} 来引用文献库中的论文了,在emcas中可以直接C-c [ 来插入,不过需要开启 reftex mode。 M-x reftex-mode <RET>开启,然后点开 Ref 选项 --> Parse Document --> Entire Document。当然也可以编辑.emacs文件,添加

  1. (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode  
  2. (setq reftex-external-file-finders   
  3. '(("tex" . "kpsewhich -format=.tex %f")   
  4. ("bib" . "kpsewhich -format=.bib %f")))  

>> An example

  1. \documentclass[11pt,a4paper]{article}  
  2. \usepackage{bm} % for math symbols bold  
  3. \usepackage{amsmath,amssymb,amsfonts}  
  4.   
  5. \title{A short Note on Everything\\[1ex] \begin{large} \LaTeX{} is  
  6. cool \end{large}}  
  7. \author{Ganquan Mao}  
  8. \date{}  
  9.   
  10. \bibliographystyle{ieeetr}  
  11. \begin{document}  
  12. \maketitle  
  13.   
  14. \input{seckrig}  
  15. %\include{}  
  16. an example.\cite{Journel1994}  
  17.   
  18. \bibliography{myref}  
  19.   
  20. \end{document}

p.s. In emacs, you can just type C-c [ then write a keyword, press enter to search for papers
Read more ...

Set another viewer for auctex in emacs

>> Open an tex file;
>> LaTeX -> Customize AUCTeX -> Extend this menu;
>> Then LaTeX -> Customize AUCTeX -> TeX Command -> TeX Output View Style;
>> Find a line somehow like ''Extension: ^pdf";
>> Change Command to viewer you want. e.g. evince %o %(outpage) to okular %o %(outpage);
>> Click “Save for future sessions”.
Read more ...

Linux 下批量解压文件

find -maxdepth 1 -name "*.bz2" | xargs -i tar xvjf {}  
这条命令可解压当前目录下的所有bz2文件。maxdepth表示搜索深度,1代表只搜索当前目录。

find -maxdepth 1 -name "*.tar" | xargs -i tar xvf {}  
可解压tar文件。

find -maxdepth 1 -name "*.tar.gz" | xargs -i tar zxvf {}  
可解压tar.gz文件。
Read more ...

Linux 下批量去后缀加后缀

1. 删除所有的 .xml 后缀

$ rename 's/\.xml$//' *.xml  

2. 给当前目录下所有文件加后缀 .xml

for i in *  
   do mv $i $i".xml"  
done  
Read more ...

利用 ssh -X 登录服务器打开 xterm 等

>> 首先确保 /etc/ssh/sshd_config 中

X11Forwarding yes

>> 然后在 host 上 check DISPLAY

$ echo $DISPLAY

如果显示 

:0
继续输入

$ export DISPLAY=urworkstationIP:0.0

urworkstationIP 就是你想要显示 xterm 的客户端的IP。

>> 然后登录是使用

$ ssh -X host
Read more ...

MATLAB 中用 spline 代替 solve/finvers 数字求解反函数

example:

  1. Cg=sym('exp(-((-log(u))^alpha + (-log(v))^alpha)^(1/alpha))');  
  2.   
  3. cu=diff(Cg,'u');  
  4. c=subs(cu,{'u','alpha'},[0.8,2]);  
  5.   
  6. vr=linspace(0,1,1000);  
  7. tr=subs(c,'v',vr);  
  8.   
  9. t=rand(100,1);  
  10. v=spline(tr,vr,t);  

如果直接用solve/finvers求解c。matlab提示无解。
##
cu是Cg对u的偏导,c为偏导函数中带入u=0.8 alpha=2得到的只含变量v的函数。
vr和tr是为了生成一定数量的pairs,以便spline函数求反函数的时候插值。

  1. plot(vr,tr,'--')  

可以看到c函数的图。
t为随机生成的100个点,v是这100个点对应的反函数值!
如果是:

  1. v=spline(vr,tr,t);  

那么就是简单的插值。
help spline
可以看到spline的相关功能和用法。
Read more ...

wget 使用技巧

wget 是一个命令行的下载工具。对于我们这些 Linux 用户来说,几乎每天都在使用它。下面为大家介绍几个有用的 wget 小技巧,可以让你更加高效而灵活的使用 wget。
  • $ wget -r -np -nd http://example.com/packages/
这条命令可以下载 http://example.com 网站上 packages 目录中的所有文件。其中,-np 的作用是不遍历父目录,-nd 表示不在本机重新创建目录结构。
  • $ wget -r -np -nd --accept=iso http://example.com/centos-5/i386/
与上一条命令相似,但多加了一个 --accept=iso 选项,这指示 wget 仅下载 i386 目录中所有扩展名为 iso 的文件。你也可以指定多个扩展名,只需用逗号分隔即可。
  • $ wget -i filename.txt
此命令常用于批量下载的情形,把所有需要下载文件的地址放到 filename.txt 中,然后 wget 就会自动为你下载所有文件了。
  • $ wget -c http://example.com/really-big-file.iso
这里所指定的 -c 选项的作用为断点续传。
  • $ wget -m -k (-H) http://www.example.com/
该命令可用来镜像一个网站,wget 将对链接进行转换。如果网站中的图像是放在另外的站点,那么可以使用 -H 选项。
Read more ...

利用 MATLAB 对文件批量重命名

>> matlab 中 strrep 函数可以更改文件扩展名。
>> matlab 中 unix system ! 都可以让你在 matlab 中执行系统命令。
比如:

  1. !mv a.tex b.tex  
  2. unix('mv a.tex b.tex')  
  3. system('mv a.tex b.tex')  

>> 再加上 dir 函数 以及一个 for-loop 就可以对文件进行批量重命名了。
当然,windows 下应该是用 rename 重命名。
Read more ...

Beamer 中指定 item 前面的符号


  1. \begin{itemize}  
  2.   \setbeamertemplate{itemize items}{\color{red}$\bullet$}  
  3. \item one  
  4. \item two  
  5. \item three  
  6. \end{itemize}  

$\bullet$ 可换成任何符号, 比如 \checkmark
或者

  1. \setbeamertemplate{items}[ball]  
Read more ...

Latex 如何去掉 subfigure 中标注 a, b, c 等

导言区加上
  1. \makeatletter  
  2. \renewcommand{\@thesubfigure}{\hskip\subfiglabelskip}  
  3. \makeatother  
Read more ...

terminal 下 nohup 不产生 nohup.out

$ nohup yourprogram >/dev/null 2>/dev/null &  

e.g.
$ nohup dolphin ~/ >/dev/null 2>/dev/null &  
Read more ...

Linux 中安装 Dropbox

注册点这里链接1 (你我各额外获得250M容量)
Kubuntu安装看这里:链接1链接2
Ubuntu下安装点这里:链接1
Lubuntu安装点这里:链接1 开机启动看这里:链接1
Debian下编译看这里:链接1 有代理的话看这里:链接1
翻墙看这里:链接1
增加容量:链接1

本人安装过程:
debian(64bit)
>> 解压到根目录 ~/ (解压后文件夹是隐藏的)
>> shell 中输入 
  1. ~/.dropbox-dist/dropboxd  
>> 输入帐号信息就好了

Lubuntu(32bit)
>>  同样也是下载 Dropbox daemon
  1. cd  
  2. wget -O dropbox.tar.gz http://www.dropbox.com/download\?plat=lnx.x86  
  3. tar -zxof dropbox.tar.gz  
  4. wget -nd http://dl.dropbox.com/u/6995/dbmakefakelib.py  
  5. wget -nd http://dl.dropbox.com/u/6995/dbreadconfig.py  
  6. python dbmakefakelib.py  
>> 打开还是一样 
  1. ~/.dropbox-dist/dropboxd  
>> 开机自动启动 
  1. cd ~/.config/autostart  
  2. touch Dropbox.desktop  
  3. vi Dropbox.desktop  
 If it does not work, then follow this:
Menu --> Preferences --> Default applications for LXSession --> Autostart 
Under Manual autostarted application type "dropbox start" (without quotes) and hit add.

加入如下内容
[Desktop Entry]
Encoding=UTF-8
Name=Dropbox
Comment=RunDropbox
Icon=/usr/share/icons/elementary/panel/22/dropboxstatus-logo.svg
Exec=bash ~/.dropbox-dist/dropboxd
Terminal=false
Type=Application
然后 logout login

Kubuntu(64bit)
下载 Kfilebox (选择自己需要的版本)
直接双击安装 或者用 dpkg -i
然后安提示输入信息就好了!

最后!!
注册点这里链接1 (你我各额外获得250M容量)
Read more ...