Wednesday, November 14, 2007

[Matlab] Create a figure with specified location and size

Source

Matlab Help, figure

Syntax

rect = [left bottom width height];
% The unit of rect is pixel by default.
% left = the distance between the left of the figure and the left of the screen
% bottom = the distnace between the bottom of the figure and the bottom of the screen
figure( 'Position', rect );

Code

Wednesday, November 07, 2007

[Matlab] Specify a figure to plot

Source

Matlab Help

Syntax

set(0,'CurrentFigure',figure_handle);

Code

h1 = figure;
h2 = figure;
set(0,'CurrentFigure',h1);
plot( x1, y1 );
set(0,'CurrentFigure',h2);
plot( x2, y2 );

Wednesday, October 10, 2007

[CPP] Conversion from char** to const char** Not Allowed

Source

http://coding.derkeiler.com/Archive/C_CPP/comp.lang.cpp/2004-10/1514.html

Description

If the conversion from char** to const char ** is allowed, then user may write a sequence of assignments which modifies a constant. Following is an exsample from Gianni Mariani posted at coding.derkeiler.com

const char * A[2] = { "A", "B" };
char * B[2];

int main() {
char ** b = B;
const char ** a = b; // illegal
//const char ** a = ( const char ** ) b; // BAD work-around (1)
//const char * const * a = b; // better option (2)
a[0] = A[0]; // illegal if you use (2) ok if you use (1)
b[0][0] = 'X'; // const violation - big probs if you use (1)
}

Monday, October 08, 2007

[Unix] Frequently Used Commands

grep

grep foo file
print the lines containing the pattern foo in file
ls | grep foo
print the lines from STDIN containing the pattern foo
grep -r -e 'PATTERN' ./user *.txt
Find a pattern PATTERN in all txt files, recursively search for all sub directories of directory "./user"

xrdb

xrdb RESOURCE_FILE
Load the resource file for X windows (e.g. xterm). The default resource file is ".Xdefaults"

top

top
Check the computer resource usage.

ln

ln -s
Check the computer resource usage.

find

find . -name "abcd*"
Find a file with "abcd" as part of the filename in current directory or the sub directories

Wednesday, September 26, 2007

[Matlab] Use Plain Text in labels and legends

Source

Matlab Help. Search for keyword 'interpreter'.

Description

To print the labels and the legends in plain text such that `_' and `^' will not be transcribed to subscript and superscript specifier.

Syntax

% Interpreter_type: 'latex' | {'tex'} | 'none'
set(handle, 'Interpreter', Interpreter_type );

Code

h_label = xlabel('MY_LABEL');
set(h_label, 'Interpreter', 'none');

h_legend = legend('LEG_1', 'LEG_2');
set(h_legend, 'Interpreter', 'none');

Friday, June 29, 2007

[Matlab][Debug]mxDestroyArray

Source

Matlab Help: Memory Management Compatibility Issues

Syndrome

The matlab engine properly opens and closes at the first time. But at the second attempt of starting matlab engine the error message pops up:
Forced Assertion: "Corrupted memory block found"

Cause

  • mxDestroyArray was called on a mxArray whose data was not assigned by matlab API
    mxArray *temp = mxCreateDoubleMatrix(1,5,mxREAL);
    double data[5] = {1,2,3,4,5};
    ...
    memcpy(mxGetPr(temp), data, 5*sizeof(double));
    ...
    mxDestroyArray(temp); // <-- INCORRECT. Do NOT call mxDestroyArray on temp

Solution

  • Do NOT call mxDestroyArray on such mxArray's

Thursday, June 14, 2007

C++ and C FAQ

Source

  • Comeau C++ and C FAQ
  • Embedded System Design
  • C++ FAQ LITE

    Description

    You can probably find answers to the fundamental questions about c++ programming.

    Memo

    • Constant objects can be declared with various types and user can access the address of the constant objects.
    • Enumeration Constants can only be integers and the address of enumeration constant is not available. But it also means that compilers won't generate codes for the ability to take the address, which becomes an advantage of using enumeration constants if users do not need the address of the constant.
    • When writing class template, the definition and the declaration should "be seen by compiler at the same time," which means one may 1. write both the declaration and the implementation in the same file (the .h file); 2. include the implementation file (.cpp) in the header file (.h), not include the header file in the implmenetation file. To explain this in one sentence: A class template is not a real class and the compiler will not see the functions of the class template with specified type.

  • Friday, June 08, 2007

    [LINUX] Bash Programming

    Source

    BASH Programming - Introduction HOW-TO by Mike G
    Advanced Bash-Scripting Guide by Mendel Cooper
    Bourne Shell Programming

    [LINUX] If The Script Does Not Run

    Check:

    • Is the script saved in Linux/Unix format (If saved in DOS format you may see "Command not found" error message). The command to remove the '\r' from DOS format is
      $ tr -d '\r' < DOS_file > UNIX_file
      The '<' is to input the DOS_file to command 'tr' and '>' is to output the file without '\r'. The commands including UNIX-to-DOS conversion can be found here
    • Is the script executable (if not you may see "Permission denied" error message

    Thursday, May 31, 2007

    [Software] PSPad Issues

    PSPad changes the unix permission when editing files
    Forum discussion: http://forum.pspad.com/read.php?2,18205,18205#msg-18205
    Solution:
    Program settings --> Direct edit
    [x]DontChangeFileAttribs=1

    Wednesday, April 25, 2007

    [Perl] Regular Expression With Chinese Char

    Use \Q中文字\E

    Tuesday, April 24, 2007

    Windows Batch Commands

    Source

    http://www.computerhope.com/batch.htm
    Run .bat file in a .bat file

    Codes:

    call bat1.bat
    call bat2.bat

    Monday, March 05, 2007

    [Matlab] Plot lines with different markers

    Source

    Matlab Help:
    • Find "LineSpec" to see the available markers

    Codes

    % Initialize a set of desired markers
    MarkerSet = 'x*o+s.^v';
    plot( x, y ); grid on;
    % Obtain all line handles under current axes handle
    hdl = findobj(gca,'Type','line');
    for k=1:length(hdl)
    % Assign markers to each line handle
    set(hdl(k), 'marker', MarkerSet(k) );
    end

    [Matlab] Plotyy and the Labeling

    Source:

    Matlab Help

    Codes:

    MY_XLABEL = 'This is xlabel';
    MY_Y1LABEL = 'This is y1 label';
    MY_Y2LABEL = 'This is y2 label';
    MY_Y1LEGEND = {'y1_lg1', 'y1_lg2' };
    MY_Y2LEGEND = {'y2_lg1', 'y2_lg2' };
    MY_TITLE = 'This is my title';

    [AX,H1,H2] = plotyy(x1, y1, x2, y2);
    xlabel( MY_XLABEL );
    set(get(AX(1),'Ylabel'),'String', MY_Y1LABEL );
    set(get(AX(2),'Ylabel'),'String', MY_Y2LABEL );
    legend(H1, MY_Y1LEGEND, 'Location', 'NorthWest' );
    legend(H2, MY_Y2LEGEND, 'Location', 'NorthEast' );
    title( MY_TITLE );

    Tuesday, February 20, 2007

    [HTML] Symbol Reference

    Greek, mathematical, symbolic characters, and so on.
    http://everything2.com/index.pl?node=HTML%20symbol%20reference

    Wednesday, January 17, 2007

    [Matlab] Data Clipping, saturation

    % 'x > upperbound' evaluates to a logical index
    x = array to be clipped;
    x( x > upperbound ) = upperbound;
    x( x < lowerbound ) = lowerbound;

    Tuesday, January 02, 2007

    Quotes

    "There is only one thing more beautiful than one guitar - Two guitars" Frederic Chopin