[ Prev ] [ Index ] [ Next ]

Cheatsheet

Created Mittwoch 20 April 2016

MATLAB callback function


--------------------

LaTex interpreter for MATLAB's figure


figure;
xlabel('$t$', 'Interpreter','latex')
ylabel('$x(t)$', 'Interpreter','latex')
title('$f(t) = x(t)$', 'Interpreter','latex')

--------------------

Set default font for MATLAB figure


set(0, 'DefaultAxesFontSize',18)

--------------------

Makefile for Xenomai application


Assume test.c is the file that we want to compile:

target = test
skin = native
CC := $(shell xeno-config --cc)
CFLAGS := $(shell xeno-config --skin=$(skin) --cflags)
LDFLAGS := $(shell xeno-config --skin=$(skin) --ldflags)
$(target): $(target).c
        $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)
clean:
        @rm $(target)

--------------------

CMake for Coin3D


project(projectname)

add_executable(projectname main.cpp)

install(TARGETS projectname RUNTIME DESTINATION bin)

link_directories(/usr/lib)

include_directories(/usr/include /usr/include/qt4 /usr/include/qt4/Qt)

target_link_libraries(libkine SoQt4 QtOpenGL QtGui QtCore  Xmu Xi Coin GL Xext SM ICE X11 dl pthread)

--------------------

MATLAB surface plot of point clouds


Assume we have 3D point clouds: x (Nx1), y (Nx1), and z (Nx1):

dt = DelaunayTri(x, y, z);
[tri Xb] = freeBoundary(dt);
tr = TriRep(tri, Xb);
P = incenters(tr);
fn = faceNormals(tr);
trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3), 'FaceColor', 'cyan', 'faceAlpha', 0.8, 'LineStyle', 'none');

% Lighting
light('Position',[-1.0,-1.0,100.0],'Style','infinite');

lighting phong

--------------------

"Not a Number" with C (Windows)


// test_nan.cpp : Defines the entry point for the console application.
//

#ifdef WIN32
    #ifndef NAN
        static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
        #define NAN (*(const float *) __nan)
    #endif
#endif

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
        printf("%f", NAN);
        return 0;
}

--------------------

MathGL


Found MathGL in this link: http://mathgl.sourceforge.net/doc_en/Main.html
This is an example on how to use it:

#include 
#include 

int draw (mglGraph *gr)
{
    mglPoint pnt;
    pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1, 2*mgl_rnd());
    gr->Line(mglPoint(0,0,0),mglPoint(1, 1,1));
}

int main(int argc,char **argv)
{
    mglQT gr(draw,"MathGL examples");
    return gr.Run();
}

// Needed libraries: -lmgl-wnd and -lmgl

./test_mathgl.zip

--------------------

Convert PDF to JPG


convert -density 300 file.pdf file.jpg

--------------------

Uninstall Python Package


Record all installed files by reinstalling the package:
python setup.py install --record files.txt

Once you want to uninstall you can use xargs to do the removal:
cat files.txt | xargs rm -rf

Source: http://stackoverflow.com/questions/1550226/python-setup-py-uninstall

--------------------

Multiline title in MATLAB figure


s = 'line1\nline2'
title(sprintf(s));

--------------------

Filtering MATLAB


fc = 5;
f = 2*fc/1000;
[b,a] = butter(6, f, 'low');
data_filtered = filter(b,a,data);

Make sure data is column wise!
Data = [ch1_1 ch2_1 ch3_1;

ch1_2 ch2_2 ch3_2;
...]

--------------------

Remove URL links from a PDFs


Concept: disassemble and reassemble the PDF using pdftk:
mkdir temp
cd temp
pdftk ../FileWithLinks.pdf burst
pdftk *.pdf cat output ../FileWithLinksRemoved.pdf

--- or ---
A simple step to remove all the hyper links from a PDF is by printing, that is by choosing print to file option. but this process doesn't remove the highlight of the hyper link. hope this helps

Source: http://askubuntu.com/questions/106154/open-source-command-line-tools-to-remove-hyperlinks-in-pdfs

---or---
pdf2ps FIle.pdf
ps2pdf File.ps

--------------------

Create parallel jobs in MATLAB


    j = createJob(c);
    
    createTask(j,@fn1, 1, {param1, param2});
    
    createTask(j,@fn2, 1, {param1, param2});
    
    submit(j);
    wait(j);
    delete(j);
    function output = fn1(param1, param2)
    	output = 1;
    end
    
    function output = fn2(param1, param2)
    	output = 1;
    end

function fn1 and fn2 MUST have output, otherwise wait(j) fails!!

--------------------

IEEE PDF setting


./IEEE_PDF_Create.zip
./IEEEPDFSpec.pdf
http://www.ieee.org/conferences_events/conferences/organizers/pubs/preparing_content.html

--------------------

VTK Boundary Edges


http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/BoundaryEdges

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
int main(int, char *[])
{
  vtkSmartPointer diskSource =
    vtkSmartPointer::New();
  diskSource->Update();
 
  vtkSmartPointer featureEdges =
    vtkSmartPointer::New();
  featureEdges->SetInputConnection(diskSource->GetOutputPort());
  featureEdges->BoundaryEdgesOn();
  featureEdges->FeatureEdgesOff();
  featureEdges->ManifoldEdgesOff();
  featureEdges->NonManifoldEdgesOff();
  featureEdges->Update();
 
  // Visualize
  vtkSmartPointer edgeMapper =
    vtkSmartPointer::New();
  edgeMapper->SetInputConnection(featureEdges->GetOutputPort());
  vtkSmartPointer edgeActor =
    vtkSmartPointer::New();
  edgeActor->SetMapper(edgeMapper);
 
  vtkSmartPointer diskMapper =
    vtkSmartPointer::New();
  diskMapper->SetInputConnection(diskSource->GetOutputPort());
  vtkSmartPointer diskActor =
    vtkSmartPointer::New();
  diskActor->SetMapper(diskMapper);
 
  // Create a renderer, render window, and interactor
  vtkSmartPointer renderer =
    vtkSmartPointer::New();
  vtkSmartPointer renderWindow =
    vtkSmartPointer::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer renderWindowInteractor =
    vtkSmartPointer::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);
 
  renderer->AddActor(edgeActor);
  renderer->AddActor(diskActor);
  renderer->SetBackground(.3, .6, .3); // Background color green
 
  renderWindow->Render();
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;
}

--------------------

Get all repos from Bitbucket


./getAllRepos.sh

--------------------

CMake for Eigen 3


cmake_minimum_required(VERSION 2.6)
project(fun_with_eigen)

find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
    PATHS
    ${CMAKE_INSTALL_PREFIX}/include
    ${KDE4_INCLUDE_DIR}
    PATH_SUFFIXES eigen3 eigen
)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Eigen3 REQUIRED)

INCLUDE_DIRECTORIES ( "${EIGEN3_INCLUDE_DIR}" )

add_executable(fun_with_eigen main.cpp)

install(TARGETS fun_with_eigen RUNTIME DESTINATION bin)

--------------------

Writing math formula in Bitbucket


Use rst format and add the following header:

.. -*- rst -*- -*- restructuredtext -*-

.. This file should be written using the restructure text
.. conventions.  It will be displayed on the bitbucket source page and
.. serves as the documentation of the directory.

.. default-role:: math

Example:  
`18^6\approx 10^8`

--------------------

Find all connected IPs in the network


http://superuser.com/questions/261818/how-can-i-list-all-ips-in-the-connected-network-through-terminal-preferably

sudo arp-scan --interface=eth0 --localnet

--------------------

VBox disk to VMWare


http://www.dedoimedo.com/computers/virtualbox-convert.html

--------------------

Statistics online learning


https://onlinecourses.science.psu.edu/statprogram/

--------------------

Drawing plane in MATLAB


A plane is defined by:

x = [1 -1 -1 1]; % Generate data for x vertices
y = [1 1 -1 -1]; % Generate data for y vertices
z = -1/C*(A*x + B*y + D); % Solve for z vertices data
patch(x, y, z);