Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing MATLAB code in Visual Studio

Is there a MATLAB add-in to Visual Studio?

I found an old one that works with Visual Studio 6. There's also the Eclipse plugin, but I prefer Visual Studio as an IDE.

like image 282
zmbq Avatar asked May 31 '13 05:05

zmbq


People also ask

Can you code MATLAB in Visual Studio?

The MATLAB® Coder™ Interface for Visual Studio® Code™ Debugging support package allows you to use Visual Studio Code to view and debug C and C++ code. For example, code that you generate from MATLAB code and Simulink® models or code that you import from external libraries.

How do I run a MATLAB script in Visual Studio?

Open the command palette (under "View" or with shortcut ctr+shift+p) and find the "Run Matlab File" command.

What is MATLAB syntax?

Command Syntax and Function SyntaxIn function syntax, inputs can be data, variables, and even MATLAB expressions. If an input is data, such as the numeric value 2 or the string array ["a" "b" "c"] , MATLAB passes it to the function as-is. If an input is a variable MATLAB will pass the value assigned to it.

How do I run a MATLAB code?

On the Editor or Live Editor tab, in the Section section, select Run and Advance. Run the code in the selected section, and then run all the code after the selected section. On the Editor or Live Editor tab, in the Section section, select Run to End. Run to a specific line of code and pause.


1 Answers

However familiar you are with VS, I would recommend abandoning it when you use Matlab. I've used multiple IDEs while developing code for Matlab, and I always come back to the built-in editor.

Matlab's editor is easy to use, and fully integrated with the program. Since Matlab is a scripting language, the debugger is also very flexible and interactive.

There are many useful features of the editor that would be (most likely) impossible in VS, including:

  • Group your code into "cells", which allow you to evaluate blocks of code on the fly
  • select some portion of your code, and evaluate it
  • an interactive variable editor, which is available both during debug mode, and outside of it
  • a command window that allows you to evaluate commands
  • a powerful command history, which allows you to view and evaluate past commands.
  • evaluate commands or other blocks of code while in debug mode. In fact, you can call any piece of code while debugging, and even debug that code as well!
  • tab completion for all variables, and functions currently on the Matlab path
  • The M-Lint feature helps improve code quality by providing feedback (in the form of underlines) on both errors and questionable usage

An example: You are debugging a function, and you come to a tricky line of code to debug. Instead of stepping over that line, you can highlight it and evaluate it in the command window, or even some small portion of the line. In this way, you can fix your code iteratively without ever leaving the debugger.

The only time I would recommend using VS for Matlab, is when writing/debugging MEX functions. You won't use VS to compile them, but VS is definitely a better IDE for writing C/C++ code.

When developing software, always use the IDE that is best suited for what you are doing. Learning a new IDE can be daunting, but Matlab's editor has a relatively low learning curve compared to others.

like image 102
hoogamaphone Avatar answered Sep 28 '22 11:09

hoogamaphone