Friday, August 8, 2014

Call C++ Function in Matlab

mex -setup %choose compiler
mex mycode.c %call the function


If you need to add other cpp files and lib files while compiling in Matlab:

mex cpp-file-for-matlab.cpp ../addthis.cpp ../addthat.cpp -laddlibrary

Tuesday, August 5, 2014

PCL Concavehull Fails


...with message saying "The initial hull is narrow (cosine of min. angle is 0.999999999999998). A coplanar point may lead to a wide facet..."

It stops complaining when I set the concavehull dimensions to 2, instead of letting the function decide by itself. It is done by adding the following line;

chull.setDimension(2);

Friday, August 1, 2014

Write C++ Code Process Time on Console

#include <time.h>
time_t start,end;
time (&start);
.
.
.
<code>
.
.
.
time (&end);
double dif = difftime (end,start);
cout<< "Elasped time is " << dif <<" seconds." << "\n" << endl;

File Cannot Be Found - Lovely Crash

...instead of crashing without any error messages

std::ifstream ifs (mystr, std::ios::in | std::ios::binary);

if (ifs.is_open()) {
        cout<<"The file is read successfully! :)"<<endl;}

else {
        // show message:
        cout << "Error opening file!"<<endl;
        cout << "The file cannot be found in the given path."<<endl;
        cout<< "The program will be closed." <<endl;
        system("PAUSE") ;
        exit(EXIT_FAILURE);
 }

Add Environment Variables in C++ Code

char *shell;


/* Get the path of the current shell to start it later */
shell = getenv("SHELL");
if (shell == NULL) {
    fprintf(stderr, "Error eding SHELL env. var.\n");
    return 1;
}       

/* Overwrite env. var. PATH */
if (setenv("PATH", "/usr/bin", 1) < 0) {
    fprintf(stderr, "Error setting env. var.\n");
    return 1;
}
Check also: http://linuxconfig.org/set-and-get-environmental-shell-variable-using-c 

Setting Jupyter and Tensorflow on Google Cloud Platform

https://towardsdatascience.com/running-jupyter-notebook-in-google-cloud-platform-in-15-min-61e16da34d52