How do I use MATLAB in Visual Studio 2010 - matlab

Is there any way to write programs in MATLAB(mex files) by using Visual Studio 2010?
If yes, then is it possible without installing MATLAB application.

You can write MATLAB programs in any tool you like that includes a text editor, including Visual Studio or just Notepad.
But to run them you need MATLAB. There is a free package called Octave that is partly compatible with MATLAB and will run many basic MATLAB programs, but not all.

Related

How to get Visual Studio Code language support to recognize new functions in SQL syntax highlighting

I develop SQL scripts on Visual Studio Code for Mac (version 1.74.3). In writing dbt models (which are SQL scripts), Visual Studio Code does not recognize certain functions (INITCAP) in one instance as a built-in function and does not highlight this as such. Not the biggest deal, but this got me wondering if I can add INITCAP or other functions to a file or something to get VSC to treat it as a function name. Please help! I search though many Microsoft documentations, but cannot find it. Oh, my files have a .SQL extension so for the most part, the file is recognized as a SQL script.

How do I run MATLAB (.m) files in VSCode?

I am not able to figure out how to run MATLAB (.m) code in VSCode.
I have installed the MATLAB Extension for VSCode and added the path for the mlint file for MATLAB as stated in the extension.
"matlab.mlintpath"
VSCode identifies the file as a MATLAB file. However, the code won't run.
How can I run MATLAB code from within VSCode?
There is a way, this VSCode extension suggests that you can use it to run MATLAB code from within VSCode without having to open the MATLAB GUI. It does not invalidate the below though; you need to have a working, licensed MATLAB installation, which will be called in the background. Without a working, licensed MATLAB installation you cannot run MATLAB code.
As MATLAB is proprietary, there are only two ways to run MATLAB code: by running the code from the MATLAB IDE (with a valid license of course), or by compiling it to an executable file with the MATLAB compiler.
You might be able to get other IDEs to have syntax highlighting and typing-hints like MATLAB's own IDE through importing its mlint functionality, like you did, but that won't execute the code.
Thus no, you cannot execute MATLAB code directly within VSCode, you can only covertly call the MATLAB engine from inside VSCode.
A possible workaround would be to export your MATLAB code to C/C++ using the MATLAB Coder. You can then run the C/C++ code from within VSCode.
TL;DR:
I wrote Matlab Terminal Extension for VS Code on Linux. It can run matlab files and spawn a matlab-Terminal. You can find the repo here.
MatTer for VS Code
I recently wanted to used a matlab terminal in vscode. There even is an extension for this. But while using the extension I faced some flaws. Also the repository does not seem to be active anymore and the owner doesn't react to issues and similar.
So I decided to write my own first extension MatTer for VS Code and published it to the VS marketplace. It's in early Development, but it can already spawn a matlab-Terminal and run matlab files.
The repo is hosted on Github, see here: https://github.com/mauzigoe/matter-for-vscode
To install it via vscode just search for matter-for-vscode in Extension.
Critics and Feedback is welcomed, esp. since I'm new to this.
"#Liam the long discourse is necessary, because having the extension without a valid MATLAB license+installation won't work.T"
...because at some point you need at least ONE working matlab install just to develop the m-file :)
I suspect that you're right, and it comes down to a choice between embedding "foreign" code into an m-file, or making calls to the matlab engine from within a foreign IDE. They do have a free RTE but you still need some form of Matlab IDE to write in plus the Matlab Compiler toolbox to build the project out for the RTE.
The work-around is to use OS tools to remove Matlab and other proprietary tools from the loop entirely. That is why if you're going to be forced to pay $5k for a proprietary tool, it has to be justified in other ways than "it can get the job done".
VS Code extensions have the same problem as any other extension: if you look at the repository and see what is required to install and run the extension? You'll probably never install an extension again. It's about as wise as blithely downloading and installing any code from the Internet: it's no better than the source. I would wait until you figure-out how to call getOpen() etc within VS Code without downloading some random extension from some random source especially one that hasn't been updated in the past 2 years. Or at least use VS2019 Community:
https://www.mathworks.com/matlabcentral/answers/100603-how-can-i-compile-a-matlab-engine-application-using-microsoft-visual-studio-9-0-or-10-0
you could use the "Matlab Interactive Terminal" Extention, the link is below.
To use it, you need to follow the instruction to install a "MATLAB Engine API for Python" and you are good to go (and you need a working Matlab).
after installing the extension, you could open the Matlab terminal in the command window (by pressing Ctrl+Shift+P and input "Open a Matlab Terminal"), and you could get the same Matlab terminal as in the real Matlab IDE, and now you could run .m code in Vscode.
You can use the Code Runner extension and put this line in your settings.json:
"code-runner.executorMapByFileExtension": {
".m": "cd $dir && matlab -batch \"$fileNameWithoutExt\""
}
You would probably also want to install the MATLAB extension.

How to Run C and C++ Programs on VS code?

As per my question, I want to compile & run c/c++ program directly from Visual Studio Code (vscode).
so is there anything like live server (like HTML) when I save file it gets compiled and runs automatically...
C++ support for Visual Studio Code is currently experimental. You may have look at this extension to accomplish what you ask.

How to create .mex file with Parallel Studio XE 2015 and Matlab 2012a?

I use Matlab 2012a while the Fortran compiler is VS2013 + Intel® Visual Fortran x15 in Windows 10. Unfortunately,my MATLAB version does not support my Intel Visual Fortran Composer for Fortran along with VS 2013. Is there a way I can edit the mex options so MATLAB recognizes the new compilers? Or do I have to move to the latest Matlab version(undesirable)?
One closely related thread on Matlab user support forum raised my hope to resolve this problem, but I don't quite understand how to adjust the xml file to my Fortran compiler (the compiler's path has already been added to the environment path). Could someone kindly explain the procedure in details?

No supported Visual C/C++ compiler found. Check your installation of Visual C/C++

I am using Matlab R2013a. The problem appears when I try to use Simulink Coder to generate Visual C++ code.
I've got this error even though I have Visual Studio 2013 installed on my computer already. When I look at list of programs that are installed on my computer I see Visual C++ 2008, 2010 and 2012. When I type the command mex -setup Matlab just can see a compiler LCC. But I need a Visual C++ compiler (which , technically, I already have) seen by Matlab.
How can I do that? Isn't mex -setup the right code?
You need MATLAB R2014a since support for Visual C++ 2013 was not added until MATLAB R2014a.
As a workaround, you can use this or this FileExchange submission to add support for building MEX files using Visual C++ 2013 with earlier MATLAB version.