• 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 C++ Question

Earwax

Senior member
I got two quick questions.

I have two matlab .m files that comprise a program. One file is the sort of "main" file with the bulk of the execution code, the second file is a function definition for a function that the first file uses. I'm not very familiar with matlab and I'm wondering how can I get the program to run. Everytime I try it will only let me run one file, and when I try to compile the files into one file it gives me an error about functions not being allowed in scripts. Is there a way to link the files when I compile? It's got to be easy to do, I'm just not experienced at it at all.

The other question I had regards a small bug I've had using Visual C++ in windows. I have a program that prompts for a path in a console. The problem is that when the path is typed in, the program disregards white space in the folder names. I believe I'm using getline to get the path. Is there a special symbol for a space used by windows that I need to type instead? I tried %20, but that didn't work.

Thanks in advance for any advice.
 
Matlab

There are two kinds of m-files in Matlab. "Script" m-files, and "function" m-files. The script files are, in short, a way of putting a lot of commands you'd type at the console in one place, to run them in order. The function files behave more like traditional programs which you call from other places (including the console, of course).

It sounds like you tried to put the contents of the function file into a script file, which you cannot do. However, you can call the function if you keep the files separate (and if you really defined the function in a function m-file). If you have things set-up that way, and both files are in the Matlab path, you should be able to run your program by simply entering the name of the script file at the console prompt. I use a Windows version of Matlab, so I have a "path browser" somewhere in the menues. I'm not sure how to set the path with a *nix version.
 
like oboeguy said, make sure your files are separate. then you can mcc (compile) them, just as long as they're in the path. This'll create MUX files on *nix, and dll's in Windows.

You can find a lot of info on using MCC at matlab's homepage (through mathworks.com)
 
Back
Top