Using MATLAB with PHP (with parameters)

 $command = "matlab -sd ".$inputDir." -r phpcreatefile('".$outputDir."\\".$filename."')";
 exec($command);
  • 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

<?php
$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) ""
?>

var_dump()

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

4unse($array)

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
var_dump($key);

via http://www.danpearce.co.uk/php_and_matlab

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com 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

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

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

%d bloggers like this: