Execute matlab files from C sharp

Hello everyone,
I am trying to write a simple C sharp program that runs a matlab script. I tried executing the .bat file, passing the argument -r "file.m" but it just opens the matlab GUI without executing the file. I would also like to pass a reference value (in my case the name of a database from which matlab should read while executing the script). How could I do that?
Thanks, mattia

 採用された回答

Walter Roberson
Walter Roberson 2011 年 8 月 7 日

0 投票

Your -r argument should be the command to execute, such as -r "file" without the .m .
If you also want to pass a reference value, then because it is a script instead of a function, you will need to do so as an assignment, such as
matlab -r "databasename='romulus';file"
Something else you should know when using -r is that it is safer to put in the "quit", and safer yet to ensure that the quit always happens even if there is an error. For example,
matlab -r "try databasename='romulus';file;end;quit"

その他の回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2011 年 8 月 7 日

0 投票

You might also want to explore interfacing with MATLAB by starting it as a COM Server from your C# application.

1 件のコメント

mattia
mattia 2011 年 8 月 8 日
thanks for the tip!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by