Vincent Garcia, Ph.D.

I am currently looking for career opportunities. Feel free to contact me!

How to?

Matlab

How to compile mex files with Visual Studio 2005 Express Edition compiler?
  • Download and install Visual C++ 2005 Express Edition.
  • Download and install the Windows Platform SDK. The download is called "Microsoft Platform SDK for Windows Server 2003 R2."
  • Install Matlab
  • Set the MSSDK environment variable. Set the environment variable by going to Start > Control Panel > System > Advanced (tab) > Environment (button) and then create a New System Variable, with name MSSDK, and value C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\ (or whichever directory you installed the Platform SDK to).
How to remove margins in Matlab figures?

When you create a figure under Matlab, margins are automatically inserted in the figure. If you save your figure for instance in an EPS file, and then if you insert your figure in a LaTeX file, a lot of space is lost to display these margins. The solution is to modify the Position property :

	figure
	x=-10:10;
	plot(x,x.^2);
	xlabel('xlabel');
	ylabel('ylabel');
	ti = get(gca,'TightInset');
	set(gca,'Position',[ti(1) ti(2) 1-ti(3)-ti(1) 1-ti(4)-ti(2)]);
	
How to plot a smooth curve with few markers?

Let us consider the following matlab code:

	x = 0:0.01:20;
	y = cos(x*pi/2) .* log(x);
	plot(x,y,'-or');
	legend('y = cos(x)')
	

The created figure shows a smooth line with a lot of markers. In fact, there are soo many markers that it is not really possible to see the main curve. So, let's display less markers:

	x = 0:1:20;
	y = cos(x*pi/2) .* log(x);
	plot(x,y,'-or');
	legend('y = cos(x)')
	

Now, there are few markers but the curve is not smooth enough. One can try to plot first the curve and second the markers:

	x = 0:0.01:20;
	y = cos(x*pi/2) .* log(x);
	x2 = x(1:50:end);
	y2 = y(1:50:end);
	plot(x,y,'-r'); hold on;
	plot(x2,y2,'or');
	legend('y = cos(x)')
	

But in this case, the legend is not correct. The solution is to directly modify the properties of the legend:

	% Create data
	x  = 0:0.1:20;
	y  = cos(x*pi/2) .* log(x);
	x2 = x(1:5:end);
	y2 = y(1:5:end);

	% Display the data
	hg = plot(x, y, '-b', x2, y2, 'or');
	ylim([-4,4])

	% Modify the legend
	[a,b,c,d] = legend('My curve');
	set(b(2),'LineStyle','-','Color','b');
	set(b(3),'Marker','o','MarkerEdgeColor','r');
	

One can also decide to group plots:

	% Create data
	x  = 0:0.01:20;
	y  = cos(x*pi/2) .* log(x);
	x2 = x(1:50:end);
	y2 = y(1:50:end);

	% Display the data
	hg = plot(x, y, '-b', x2, y2, 'or');
	ylim([-4,4])

	% Create a group
	my_group = hggroup;
	set(hg, 'Parent', my_group)
	set(get(get(my_group, 'Annotation'), 'LegendInformation'), 'IconDisplayStyle', 'on');

	% Modify the legend
	[a,b,c,d] = legend('My curve');
	set(b(2),'LineStyle','-','Color','b');
	set(b(3),'Marker','o','MarkerEdgeColor','r');
	
The "PDF curse" of Matlab

Have you ever tried to generate a PDF file from a Matlab figure? Well, I've tried and I failed... This section is just to explain you the problem I have. Matlab is an expert in the generation of figures. However, the PDF exportation is, for me, difficult to understand. Let's try something together. Copy/paste the following code in Matlab:

	    % Define x and y values
        x = -10:0.01:10;
        y = cos(x);

        % Plot the function
        figure('Position',[300,300,400,400])
        plot(x,y)
        ylim([-2,2])
        xlabel('x')
        ylabel('cos(x)')
	

You will see a beautiful figure displayed. Now try to save this figure as follow:

  • use the commande line saveas(gcf, 'myFigure.pdf', 'pdf') to save your figure in a file named myFigure.pdf
  • use the save as button to save your figure in a file named myFigure2.pdf

First, if you now compare the two PDF files, you will see first that myFigure.pdf do not respect the original figure aspect. Second, you can see that the curve of myFigure.pdf is more or less smooth while the curve of myFigure2.pdf is clearly not. Bellow, I present you a close up on the two curves, myFigure.pdf on the left hand side and myFigure2.pdf on the right hand side.


PDF curse

I think there should be a way to obtain a figure with a smooth curve and with the correct aspect. So if you know the answer, please let me know :-)

CUDA

How to compile CUDA code with Cygwin?
  1. Download and install Visual C++ 2005 Express Edition.
  2. Download and install graphic card drivers supporting CUDA on CUDA zone website.
  3. Download and install CUDA toolkit on CUDA zone website.
  4. Download and install Cygwin.
  5. Add C:\Program Files\Microsoft Visual Studio 8\VC\bin to Path (Windows XP environment variable) (adapt if needed).
  6. Compile your code on Cygwin using nvcc command line.
How to use CUDA code in Matlab?
  1. Download and install Visual C++ 2005 Express Edition.
  2. Download and install graphic card drivers supporting CUDA on CUDA zone website.
  3. Download and install CUDA toolkit on CUDA zone website.
  4. Download and install the Windows Platform SDK. The download is called "Microsoft Platform SDK for Windows Server 2003 R2."
  5. Install Matlab
  6. Set the MSSDK environment variable. Set the environment variable by going to Start > Control Panel > System > Advanced (tab) > Environment (button) and then create a New System Variable, with name MSSDK, and value C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\ (adapt if needed).
  7. Add C:\Program Files\Microsoft Visual Studio 8\VC to Path (environment variable) (adapt if needed).
  8. Run Matlab
  9. Setup Mex :
    1. Run command line mex -setup
    2. To question "Would you like mex to locate installed compilers [y]/n?", answer "n".
    3. Set compiler to 14 (Microsoft Visual C++ 2005 Express Edition).
    4. Set the correct location of Microsoft Visual C++ 2005 Express Edition (typically C:\Program Files\Microsoft Visual Studio 8).
    5. Confirm.
  10. Donwload CUDA plugin for Matlab on NVIDIA website and follow instructions given in README file.
  11. Compile you CUDA/Mex code using command line nvmex.

Java

How to use doxygen in eclipse?

Doxygen is a tool for writing software reference documentation. The documentation is written within code, and is thus relatively easy to keep up to date. Doxygen can generate an on-line documentation browser (e.g. HTML) and/or an off-line reference manual (e.g. LaTeX) from a set of documented source files. Eclox is a simple doxygen frontend plug-in for eclipse. It aims to provide a slim and sleek integration of the code documentation process into eclipse by providing a high-level graphical user interface over doxygen.

Installation:

  1. Install doxygen
  2. Install the eclox plug-in
  3. Launch eclipse
  4. Open the Help content (Help > Help content )
  5. Follow the instructions given in the section Eclox guide
Why doxygen doesn't display formulas in HTML documentation?

If you use doxygen to generate your Java documentation, you can easily create HTML and LaTeX documentation in directly include LaTeX formulas in your documentation. For instance use the code \f$ x^2 \f$ to display x2 in your documentation.
However, if you have LaTeX formula displayed instead of having the compiled formula in your documentation, it means that doxygen was not able to generate images from LaTeX formulas. The reason of this is usually that doxygen is not able to find ghostscript program which should be installed in your system. The solution is simply to add the bin directory of ghostscript in the Windows path.

LaTeX

How to obtain the correct symbols for real numbers, natural numbers, rational numbers, etc. ?

Let's take the example of real number. Most of you are using the macro \textbb{R} to display real numbers and this is not correct. The best way that I've found to correctly display the number symbols is to used the dsfont package. You'll find bellow a simple LaTeX example:

     \documentclass{article}
     
     % Include the package dsfont.sty
     \usepackage{dsfont}
     
     % Beginning of the document
     \begin{document}
         This is the symbol for real numbers     : $\mathds{R}$ \\
         This is the symbol for natural numbers  : $\mathds{N}$ \\
         This is the symbol for rational numbers : $\mathds{Q}$ \\
         This is the symbol for complex numbers  : $\mathds{C}$ \\
     \end{document}
	
How to align text in columns ?

If you want to align some text in columns without using a table (I guess most of you are using the tabular environment), LaTeX provides the very useful tabbing environment. It works by setting tab stops and tabbing to them much the way you do with an ordinary typewriter. See the Help On LaTeX for more information. You'll find bellow a simple example:

    \begin{tabbing}
        This is some text \= This is more text \= And still more text \= And last text \\
        First column      \> Second column     \> Third column        \> Fourth column \\
        One               \> Two               \> Three               \> Four          \\
        Etc.              \> Etc.              \> Etc.                \> Etc.          \\
        ....
        ....
    \end{tabbing}
How to insert the bibliography into the table of content ?

A simple and classical way (but wrong way) to add the bibliography into the table of content (TOC for short) is to use the following lines of LaTeX code:

    % Bibliography
    \bibliography{bibliography}
    \bibliographystyle{alpha}
    \addcontentsline{toc}{part}{Bibliography}

By using this, you will see that the page number associated to the bibliography in the TOC corresponds to the last page of the bibliography. I'm not going to explain why here but the only working hack I've found across the Internet is the following lines of LaTeX code:

    % Bibliography
    \cleardoublepage 
    \phantomsection 
    \addcontentsline{toc}{part}{Bibliography}
    \bibliography{bibliography}
    \bibliographystyle{alpha}

Basically, the page number associated to the bibliography in the TOC actually corresponds to the beginning of the phantom section. This hack of course works for the list of figures, list of tables, etc.:

    % List of figures
    \cleardoublepage 
    \phantomsection
    \addcontentsline{toc}{part}{List of figures}
    \listoffigures

    % List of tables
    \cleardoublepage 
    \phantomsection
    \addcontentsline{toc}{part}{List of tables}
    \listoftables

Miscellaneous

How to remove (crop) the white margins of PDF file?

If, for instance, you save a figure done in Matlab into a PDF file (myFile.pdf), you'll see that your figure has huge white margins (A4 paper). Then, if you want to include this figure in your publication, you either have to remove the white margins, or you have to use another image format such as PNG or JPEG. The first option is more adapted to publications as it keeps the vectorial property of the figure. Thanks to Olivier Schwander who told me the trick, here is the solution. juts use the following command line:


pdfcrop myFile.pdf

This command creates a file myFile-crop.pdf and is available in every OS: Linux, Windows (using Cygwin), and Mac OSX.

How to convert EPS files to PDF?

If you have an EPS file (myFile.eps) and if you want to properly convert it in a PDF file, the best way is to use the ps2pdf command line function. Used with the correct options, it's possible to desable image compression and export a correct bounding box. Under windows, I personnaly use Cygwin to do this convertion.


ps2pdf -dEPSCrop -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode myFile.eps

If you want now to convert several EPS files to PDF (batch conversion), if think that the best way is to use the following simple shell script:


for i in `ls *.eps`
do
echo $i
ps2pdf -dEPSCrop -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode $i
done


This script applies the ps2dpf command line function to every EPS files listed in the current directory. To run the script (copy/paste in a file named for instance myScript.sh) under Cygwin, just run ./myScript.sh.

How to convert a video for Powerpoint?

Have you already tried to include a video to your Microsoft Powerpoint presentation? I'm shure that you have many problems to do that. Problem: the video (format) is not reconized by Powerpoint. Solution: convert your video to a format recognized by Powerpoint. I propose bellow a short method to do it for free under Windows. The operation is exactly the same under Linux or or Mac OS X, the difference being just the software used.

  1. Download, install and run SUPER
  2. Drag and drop your video file into the input area
  3. Choose the Output container WMV
  4. Choose the Output video codec MS-MPEG4-V2
  5. Choose the Output audio codec WMA
  6. Press Encode button

Your video has been saved in the Outpout directory located in the SUPER installation directory.
SUPER doesn't exist under Linux and Mac OS X. So, for Linux, you can use FFMPEG, and for Mac OS X, you can use FFMPEGX.

How to use CImg library with Visual C++ 2005 Express Edition?
  1. Download CImg library.
  2. Download and install Visual C++ 2005 Express Edition.
  3. Download and install Microsoft Windows SDK.
  4. Configure Visual C++ to take into account Microsoft SDK
    1. Go to menu "Tools -> options".
    2. Select option "Projects and Solutions -> VC++ Directories".
    3. In the select liste "Show directories for", choose "include files", and add C:\Program Files\Microsoft Platform SDK\Include (adapt if needed).
    4. In the select liste "Show directories for", choose "library files", and add C:\Program Files\Microsoft Platform SDK\Lib (adapt if needed).
  5. Edit file C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults\corewin_express.vsprops (adapt if needed).
  6. Remplace the line
    AdditionalDependencies="kernel32.lib" />
    by
    AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib" />.
  7. Restart Visual C++.
  8. Import CImg library in your main file.
How to compile CMake project in Eclipse?

You have a CMake project (e.g. C++) that you want to edit and compile in Eclipse? The procedure is quite easy. Let us assume that your project has the following organization:
project / src
project / build
The src folder contains the source code, and the build folder contains the result of the compilation.

  1. Go to the build directory and execute the following command line:
    cmake -G"Eclipse CDT4 - Unix Makefiles" -DECLIPSE_CDT4_GENERATE_SOURCE_PROJECT=TRUE ../src
  2. Execute make
  3. Launch Eclipse
  4. Import the CMake project using Menu File->Import.
  5. Select General->Existing projects into workspace.
  6. Browse where your build folder is. Keep "Copy projects into workspace" unchecked. Then click "Finish".
  7. Enjoy!