(858) 586 7777 | About | Testimonials | Contact
vteams vteams vteams vteams
  • How does it work?
    • Startup Process
    • Your First Day
  • Technologies
    • Hire PHP Developer
    • Hire App Developer
    • Hire JavaScript Developer
    • Hire ROR Developer
    • Hire IOS Developer
    • Hire .NET Developer
    • Hire AI Developer
    • Hire Robotics Engineer
  • Sample Budgets
  • Meet The Team
  • Experiments
  • Captain’s Log
  • Blog
vteams vteams
  • How does it work?
    • Startup Process
    • Your First Day
  • Technologies
    • Hire PHP Developer
    • Hire App Developer
    • Hire JavaScript Developer
    • Hire ROR Developer
    • Hire IOS Developer
    • Hire .NET Developer
    • Hire AI Developer
    • Hire Robotics Engineer
  • Sample Budgets
  • Meet The Team
  • Experiments
  • Captain’s Log
  • Blog
Blog
  1. vteams
  2. Blog
  3. PHP and MATLAB Interfacing
Feb 23
vteams- blog

PHP and MATLAB Interfacing

  • February 23, 2016

In a project, the interfacing of PHP and MATLAB was required as client wanted the calculation of calories and quantity from a provided food image. Pre-requisites for this project were to have MATLAB installed on either Windows or Linux machine along with the Web server set up on the same machine. Before working on the actual project, we created a working demo for testing purposes.

In this demo, MATLAB file was doing calculations and saving the data in a file. PHP script then executed this functionality and later on displayed the result of that particular file.

MATLAB Code:

The created MATLAB file was performing addition operation. The result was saved in a result.txt file as:

MATLAB
1
2
3
4
5
6
7
A = 5;
B = 5;
C = A + B;
 
fileID = fopen('result.txt','w');
fprintf(fileID,'%6.2f\n',C);
fclose(fileID);

PHP Code:

The PHP code given below will call MATLAB file to calculate and save the data in result.txt file.

Note: This is a very simple and short example, there can be better ways to write the same functionality.

Provided a 5 seconds delay to the file so that MATLAB code can write the output in result.txt file. Right after 5 seconds, the calculated result from result.txt file will be displayed.

PHP
1
2
3
4
5
6
7
8
//This line will call MATLAB code
exec("\"C:\\Program Files\\MATLAB\\R2011a\\bin\\matlab.exe\" -nodisplay -nosplash -nodesktop -r \"run('C:\\Users\\Administrator\\Desktop\\myfile.m')\"");
 
// 5 Seconds delay
sleep(5);
//Print Saved results from file
$c = file_get_contents('C:\\Users\\Administrator\\Desktop\\result.txt');
echo $c;

In this code, PHP execution function was used to execute .m file of MATLAB.  After that, a 5 seconds pause was set for MATLAB code processing. file_get_contents function would then get recently written content from result.txt file. At the end, fetched result would be printed.

  • Facebook
  • Twitter
  • Tumblr
  • Pinterest
  • Google+
  • LinkedIn
  • E-Mail

Comments are closed.

SEARCH BLOG

Categories

  • Blog (490)
  • Captain's Log (1)
  • Closure Reports (45)
  • Experiments (7)
  • How-To (56)
  • Implementation Notes (148)
  • Learn More (156)
  • LMS (8)
  • Look Inside (10)
  • Operations Log (12)
  • Programmer Notes (20)
  • R&D (14)
  • Rescue Log (4)
  • Testimonials (25)
  • Uncategorized (4)

RECENT STORIES

  • GitHub Actions- Automate your software workflows with excellence
  • Yii Framework – Accomplish Repetitive & Iterative Projects with Ease
  • A Recipe for CRM Software Development
  • Are Agile and DevOps the same?
  • The Data Scientist’s Toolset

ARCHIVES

In Short

With the vteams model, you bypass the middleman and hire your own offshore engineers - they work exclusively for you. You pay a reasonable monthly wage and get the job done without hassles, re-negotiations, feature counts or budget overruns.

Goals for 2020

  • Open development center in Australia
  • Complete and Launch the Robot
  • Structural changes to better address Clients' needs

Contact Us

Address: NEXTWERK INC.
6790 Embarcadero Ln, Ste 100,
Carlsbad, CA 92011, USA

Tel: (858) 586 7777
Email: fahad@nextwerk.com
Web: www.vteams.com

© 2020 vteams. All Rights Reserved.

Content Protection by DMCA.com