本文介绍了编译后的Matlab代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全是Matlab的新手我想问的是,当我们用Matlab软件或IDE编写程序并将其保存为.m(点m)文件,然后编译并执行该文件,然后将该.m(点m)文件转换为哪个文件?我想知道这一点,因为我听说Matlab是平台独立的,并且我在Google上进行了搜索,但是我将Matlab文件转换为C,C ++等很抱歉这个愚蠢的问题,谢谢您.

I am totally a newbie in MatlabI want to ask that when we write a program in Matlab software or IDE and save it with a .m (dot m) file and then compile and execute it, then that .m (dot m) file is converted into which file? I want to know this because i heard that matlab is platform independent and i did google this but i got converting matlab file to C, C++ etc Sorry for the silly question and thanks in advance.

推荐答案

Matlab是一种解释语言.因此,在大多数情况下,没有持久的中间形式.但是,有一种称为 pcode 的加密中间形式.还有MATLAB编译器和MATLAB编码器,它们以其他高级语言(例如C)提供代码.

Matlab is an interpreted language. So in most cases there is no persistent intermediate form. However, there is an encrypted intermediate form called pcode and there are also the MATLAB compiler and MATLAB coder which delivers code in other high level languages such as C.

修改:pcode不会自动生成,并且应独立于平台/版本.但是它的主要目的是加密代码,而不是对其进行编译(尽管它会进行部分编译).要使用pcode,您仍然需要安装MATLAB环境,因此在许多方面它的作用类似于解释代码.

edit:pcode is not generated automatically and should be platform/version independent. But it's major purpose is to encrypt the code, not to compile it (although, it does some partial compilation). To use pcode, you still need the MATLAB environment installed, so in many ways it acts like interpreted code.

但是根据您的后续问题,我想您不太了解MATLAB的工作原理.代码会被解释(尽管需要一点即时编译),因此不需要持久的中间代码文件:表示代码的实际数据结构由MATLAB维护.与编译语言相反,在开发周期中,您需要像编写代码,编译和链接,执行"这样的过程,而 compilation (实际上是:解释)步骤是执行的一部分,因此最终在大多数情况下使用编写代码,执行".

But from your follow-up question I guess you don't quite understand how MATLAB works. The code gets interpreted (although with a bit of Just-In-Time Compilation), so there is no need for a persistent intermediate code file: the actual data structures representing your code are maintained by MATLAB. In contrast to compiled languages, where your development cycle is something like "write code, compile & link, execute", the compilation (actually: interpretation) step is part of the execution, so you end up with "write code, execute" in most of the cases.

只是为了让您对编译器和解释器之间的区别有一些直观的了解.编译器将高级语言翻译为低级语言(例如,可以由您的计算机执行的机器代码).然后,该编译的代码(最有可能存储在文件中)将由您的计算机执行.另一方面,解释器会逐段解释您的高级代码,确定在程序运行期间与您的高级代码相对应的机器代码,然后立即执行该机器代码.因此,并没有真正需要与整个程序等效的机器代码(因此,在很多情况下,解释器不会存储完整的机器代码,因为这只是浪费的精力和空间).

Just to give you some intuitive understanding of the difference between a compiler and an interpreter. A compiler translates a high level language to a lower level language (let's say machine code that can be executed by your computer). Afterwards that compiled code (most likely stored in a file) is executed by your computer. An interpreter on the other hand, interprets your high level code piece by piece, determining what machine code corresponds to your high level code during the runtime of the program and immediately executes that machine code. So there is no real need to have a machine code equivalent of your entire program available (so in many cases an interpreter will not store the complete machine code, as that is just wasted effort and space).

您可以或多或少地看解释,就像人类会解释代码一样:当您尝试手动确定某些代码的输出时,您会逐行遵循计算并跟踪结果.通常,您不会将整个代码转换为其他形式,然后再执行该代码.而且,由于您不完全翻译代码,因此无需持久存储中间形式.

You could look at interpretation more or less as a human would interpret code: when you try to manually determine the output of some code, you follow the calculations line by line and keep track of your results. You don't generally translate that entire code into some different form and afterwards execute that code. And since you don't translate the code entirely, there is no need to persistently store the intermediate form.

如上所述,您可以使用其他工具,例如 MATLAB编码器将您的MATLAB代码转换为其他高级语言,例如C/C ++,或者您可以使用 MATLAB编译器,将您的代码编译为依赖于某些运行时库的可执行形式.但是这些仅在非常特殊的情况下使用(例如,当您必须在没有MATLAB的计算机/嵌入式设备上部署MATLAB应用程序时,当您需要提高代码性能时...)

As I said above: you can use other tools such as MATLAB coder to convert your MATLAB code to other high languages such as C/C++, or you can use the MATLAB compiler to compile your code to executable form that depends on some runtime libraries. But those are only used in very specific cases (e.g. when you have to deploy a MATLAB application on computers/embedded devices without MATLAB, when you need to improve performance of your code, ...)

注释:我对编译器和解释器的解释是对原型解释器和编译器的快速比较.许多现实生活中的案件都介于两者之间,例如Java通常会编译为(JVM)字节码,然后由JVM进行解释,并且可以说有关.NET语言及其CLR的类似内容.

note: My explanation about compilers and interpreters is a quick comparison of the archetypal interpreter and compiler. Many real-life cases are somewhere in between, e.g. Java generally compiles to (JVM) bytecode which is then interpreted by the JVM and something similar can be said about the .NET languages and its CLR.

这篇关于编译后的Matlab代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 04:02