• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Matlab and VC++

LexPliant

Member
I am creating a dialog box with a button on it, what I want this button to do is call up matlab and run one of my M-file, I look up the Matlab help and it tells me to alter the shortcut target or create a batch file with c:\matlabsp1\bin\win32\matlab /r M_file, I create the matlab.bat. and i try to call it up in VC++ 6.0 using:

ShellExecute(NULL,"open","C:\matlab",NULL,NULL);
WinExec("c:\matlab",SW_SHOW);
system("c:\matlab");

but, all of these command just open Matlab, but it doesn't run my M_file, what I mean is that it open the matlab window only. I am using Matlab 6.1 by the way.

What did I do wrong?

please help me, my project is due March31,
 
First of all, provide a fully-qualified path and filename for the executable and/or your file, so it would be "C:\matlab.exe" in your case (or whatever the filename is). Secondly, can't you open MatLab with a certain command-line argument, e.g. "matlab.exe /open c:\file.fil" ? And it would be much easier to use a scripting/macro utility like MacroMagic if you don't need a full-blown program like you're doing 🙂
 
Originally posted by: kleinesarschloch
none of those paths are valid in C++. you need to use "\\" in string, since a single "\" is an escape character.

Ah, good one, I missed that 🙂 Due to the escaping nature of C++.
 
Originally posted by: VBboy
Originally posted by: kleinesarschloch
none of those paths are valid in C++. you need to use "\\" in string, since a single "\" is an escape character.

Ah, good one, I missed that 🙂 Due to the escaping nature of C++.

don't worry... your nickname speaks volumes... 😉
 
Originally posted by: kleinesarschloch
Originally posted by: VBboy
Originally posted by: kleinesarschloch
none of those paths are valid in C++. you need to use "\\" in string, since a single "\" is an escape character.

Ah, good one, I missed that 🙂 Due to the escaping nature of C++.

don't worry... your nickname speaks volumes... 😉

What does the thread in my signature tell you? 😉
 
Originally posted by: VBboy
Originally posted by: kleinesarschloch
Originally posted by: VBboy
Originally posted by: kleinesarschloch
none of those paths are valid in C++. you need to use "\\" in string, since a single "\" is an escape character.

Ah, good one, I missed that 🙂 Due to the escaping nature of C++.

don't worry... your nickname speaks volumes... 😉

What does the thread in my signature tell you? 😉

you really really hate flash? 😀
 
Thank you for your reply, I try the \\
now i can open Matlab, but I still can not run my M_file(my code), according to the Matlab help, it needs a command line agrument :
________________
Example - Setting the Startup Options to Automatically Run an M-File. To start
MATLAB and automatically run the file results.m, use this target path for your
Windows shortcut.

D:\matlabr12\bin\win32\matlab.exe /r results
_________________

so where should I put /r argument in the ShellExecute() function, I type this, but it only activate matlab, but it would not run my code

ShellExecute(NULL, "open", "D:\\matlabr12\\bin\\win32\\matlab.exe /r ", "C:\\results.m", NULL,
SW_SHOW);

Did i miss something?
 
try this:

ShellExecute(NULL, "open", "D:\\matlabr12\\bin\\win32\\matlab.exe ", "/r C:\\results.m", NULL,
SW_SHOW);

the "/r" is part of the parameter.
 
kleinesarschloch:

Thank you for helping, but it still give me the samething, it can only open matlab window, but it will not run my program(M_file), do anybody know are there any other way to do this?
 
Originally posted by: kleinesarschloch
Originally posted by: VBboy
Originally posted by: kleinesarschloch
Originally posted by: VBboy
Originally posted by: kleinesarschloch
none of those paths are valid in C++. you need to use "\\" in string, since a single "\" is an escape character.

Ah, good one, I missed that 🙂 Due to the escaping nature of C++.

don't worry... your nickname speaks volumes... 😉

What does the thread in my signature tell you? 😉

you really really hate flash? 😀

Flash is pure and utter evil OR crap 🙂 I have NEVER EVER seen it used for a purpose other than ads. Wait, maybe Flash games is ONE such purpose. I don't believe it has the right to exist other than that.
 
Originally posted by: LexPliant
kleinesarschloch:

Can you explain a bit more?, so I put Shellexcute(M_file) like that?

lol... hold on, let me get my spoon. 😉

::ShellExecute(0, "open", "C:\\results.m", "", 0, SW_SHOW);

what i meant was to pass the path to the file itself instead of the matlab executable. the file type needs to be associated with matlab.
 
LexPliant,

Have you by any chance verified that the Matlab instructions you've been given work correctly at a regular command prompt? In other words, open up a DOS/COMMAND window and manually type:

c:\matlabsp1\bin\win32\matlab /r M_file

When doing that, does Matlab execute as you want it to or does it sit there in the Matlab application? If it simply sits there in the Matlab application, none of the suggestions above will help you solve this problem. The first step to solving your problem is to make sure the command line execution works correctly at a plain old DOS/COMMAND prompt.
 
TheDiggler:

you have a very good point, I never thought about that, I tried few minutes ago, and suprisingly, it doesn't, oh god, the command is wrong?? but it is listed on the Matlab help, and what I get from the Mathwork technical support, they give me the same command for it matlab /r coinsregns, so for now the question is does any one know what is the right command to run matlab M_files? Thank you to all of you for your advice, most of them works, just the command for Matlab is possibly wrong.
 
If "Mathwork technical support" is the company that supports Matlab, I'd e-mail them again. Mention that you've previously received instructions from them; however, those instructions aren't working correctly. Perhaps it may be wise to attach your Matlab input file as an e-mail file attachment. Ask them precisely how to invoke Matlab in "batch" mode.

P.S. I'm completely unfamiliar w/ Matlab so I'm in no position to provide you w/ further suggestions.
 
Back
Top