Matlab “out of memory”

??? Out of memory. Type HELP MEMORY for your options.

when MATLAB says it’s out of memory, it means it’s out of contiguous memory, so rebooting or restarting MATLAB may work.

A wide range of problems can cause out of memory errors.

To diagnose, use “dbstop if all error” to set a breakpoint on errors. The out of memory will trigger this, and you can use dbup, dbdown, and whos() to see what’s consuming memory.

Often an Out Of Memory is caused by a bad array size or index calculation, not just by big data structures.



Using MATLAB with PHP (with parameters)

 $command = "matlab -sd ".$inputDir." -r phpcreatefile('".$outputDir."\\".$filename."')";
  • sd “startdir”: the startup directory for MATLAB, in this case we set it to match the location of function phpcreatefile
  • -rstatement“: starts MATLAB and executes the specified MATLAB statement.

string exec ( string command [, array output [, int return_var]])

exec() executes the given command, however it does not output anything.

  •  returns the last line from the result of the command.
  • output argument is present, the specified array will be filled with every line of output from the command.
  • Line endings, such as \n, are not included in this array.
  • Note that if the array already contains some elementsexec() will append to the end of the array.
  • If you do not want the function to append elements, call unset() on the array before passing it to exec().
  • if return_var argument is present along with the array argument, then the return status of the executed command will be written to this variable.
  • Return codes can be a bit arbitrary. Basically though, any non-zero return value is an error.
    • All exec knows about is lines of output; it has no further knowledge of what is in those lines.
      $output = array();
      exec("awk -v RS=\",\" '/some_text/' test1.html", $output);
      echo implode("\n", $output);

PHP parameters

PHP中的所有变量都是以 $ 符号开始的。不需要在设置变量之前声明该变量。根据变量被设置的方式,PHP 会自动地把变量转换为正确的数据类型。

自 PHP 3 起可用 print $HTTP_POST_VARS[‘username’];


echo $downloadFile_path.$downloadFileName;

implode — Join array elements with a string

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone
// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""


used to displays structured information (type and value) about one or more variables.


destroys the specified variables.

/*foreach($out as $line) {
echo $line;

 PHP global

get the last value & key of an array in PHP:

  • $lastValue = end($array);
    • $lastKey = key($array); // current key, which is the last since you called end()
    • end(array_keys($myarr))
  • array_pop(array_keys($array));
  • echo $array[count($array) – 1]; //This only works if you have numerical arrays. Fails with associate arrays.
  • $last_key = key( array_slice( $array, -1, 1, TRUE ) );
$array = array(
    'first' => 123,
    'second' => 456,
    'last' => 789, 
end($array);         // move the internal pointer to the end of the array
$key = key($array);  // fetches the key of the element pointed to by the internal pointer


mex dist_bw_sc_C.c in Ubuntu

>> mex dist_bw_sc_C.c

Warning: You are using gcc version "4.6.3-1ubuntu5)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:

dist_bw_sc_C.c:1:27: fatal error: common_matlab.h: No such file or directory
compilation terminated.

mex: compile of ' "dist_bw_sc_C.c"' failed.

Error using mex (line 206)
Unable to complete successfully.

~/.matlab/R2012a$ chmod a+w

sudo gedit ~/.matlab/R2012a/
replace all instances of CC='gcc' to CC='gcc-4.3'CXX='g++' to CXX='g++-4.3', and FC='gfortran' to FC='gfortran-4.3'. Save and exit.

  • linux:*.amexa64
  • windows:*.mexw64

Joining/merging several cell arrays【matlab】

all_sc=[girl_sc; jug_sc; horse_sc; pot_sc];

[error] Maximum recursion limit of 500 reached. Use set(0,’RecursionLimit’,N) to change the limit.

Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

This is happening because you have a function that calls itself recursively with no stopping condition.  it continues until you hit the maximum recursion limit error. It is the recursive equivalent of an infinite loop.

one of the (few) solutions

– you could extend your recursion limit…


– better, though, reconsider your code…

[matlab] bwlabel + find

L = bwlabel(BW, n)

Label connected components in 2-D binary image

 L= bwlabel(BW, n) returns a matrix L, of the same size as BW, containing labels for the connected objects in BW.

The elements of L are integer values greater than or equal to 0. The pixels labeled 0 are the background. The pixels labeled 1 make up one object; the pixels labeled 2 make up a second object; and so on.

n: 4 or 8, where 4 specifies 4-connected objects and 8 specifies 8-connected objects. If the argument is omitted, it defaults to 8.

[L, num] = bwlabel(BW, n) returns in num the number of connected objects found in BW.


Find indices and values of nonzero elements

[row,col,v] = find(X, …) returns a column or row vector v of the nonzero entries in X, as well as row and column indices. If X is a logical expression, then v is a logical array. Output v contains the non-zero elements of the logical array obtained by evaluating the expression X.


Numerical gradient


[error] ‘K>>’ in matlab

dbquit terminates debug mode.

K>> dbquit(‘all’)

The Command Window then displays the standard prompt (>>).

The file being processed is not completed and no results are returned. All breakpoints remain in effect, unless your file contains (and MATLAB has processed) one or more of the following commands:clear allclear functionclear classes.

If you debug file1 and step into file2, running dbquit terminates debugging for both files. However, if you debug file3 and also debug file4, running dbquit terminates debugging for file4, butfile3 remains in debug mode until you run dbquit again.

dbquit('all') or the command form, dbquit all, ends debugging for all files at once.

K>> dbstack
	  	in file1 at 11
dbstack displays the line numbers and file names of the function calls that led to the current breakpoint, listed in the order in which they were executed.

【error】Undefined function or method ‘rad2deg’ for input arguments of type ‘double’.

Reason: when the function isn’t on the MATLAB path or in pwd.

1. make sure that you are able to find the function using:

>> which rad2deg
‘rad2deg’ not found.

The return means It is not on the MATLAB path or in PWD. That is often unhelpful in this case – it tells you Matlab can’t find the file, which you knew already.

2.  make sure that the file that matlab is finding (use which) requires the same type as the first argument you are actually passing.

Basically, Matlab looks for files in:

  1. The current directory (pwd);
  2. Directly in a directory on the path (to see the path, type path at the command line)
  3. In a directory named @(whatever the class of the first argument is) that is in any directory above.


Radians To Degrees Conversion Function .

Converts the argument array from radians to degrees. The general syntax for its use is y = rad2deg(x)
Note that the output type will be the same as the input type, and that complex arguments are allowed. The output is not wrapped to [0,360).

Some known conversion factors
--> rad2deg(1) % one radian is about 57 degrees
ans =
--> rad2deg(pi/4) % should be 45 degrees
ans =
--> rad2deg(2*pi) % Note that this is 360 not 0 degrees
ans =

f0 = 60;         %frequency (Hz)
w0 = f0*pi/180;  %natural frequency (rad)

The conversion factor is not difficult, but it can be a workflow distraction nonetheless.

ans =

ans =
  • deg = rad./(pi/180);
  • ad = pi.*deg./180 ;




  • 选中你要加注释的内容,然后选择工具菜单“text|comment”就可以了, 快捷键是”Ctrl+R”
  • 采用matlab块注释方法
    %} Something
  •   在注释段前面加一行:if LOGICAL(0)
  • Matlab中单行程序分行写         Command1…         Command2…          即一行末尾加3个句点

【buzzwords】ASM, AAS,setenv

Active shape models (ASM) and active appearance models (AAM) restrict the shape deformation to a subspace to exploit the priori knowledge.

Formulated as an optimization problem, the objective function of AAM is the same for all shapes.
setenv – Set environment variable

setenv(name,value) sets the value of an environment variable belonging to the underlying operating system.

If name already exists as an environment variable, then setenv replaces its current value with the string given in value. If name does not exist, setenv creates a new environment variable called name and assigns value to it.

setenv(name) is equivalent to setenv(name, ”) and assigns a null value to the variable name.





Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web