Matlab中使用jython扩展功能
Matlab中面向对象能力并不强,通过使用jython引擎能够对其功能扩展.
1 编辑classpath.txt增加jython.jar
在matlab中输入
which classpath.txt
结果:
/usr/local/MATLAB/R2013a/toolbox/local/classpath.txt
编辑该文件,加入
/home/your_user/jython2.5.3/jython.jar
2 又一次启动matlab
3 编写代码測试
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; mg = ScriptEngineFactory();
jy = mg.getEngineByName('jython')
能够看到结果:
jy =
org.python.jsr223.PyScriptEngine@432034a
jy.eval('print("Hello")')
jy.eval('def add(a, b):\n return a + b')
jy.eval('add(5, 5)')
jy.put('name', 'Hello')
jy.get('name')
v = rand(5, 5)
jy.put('vals', v)
jy.get('vals')
假设希望使用其它脚本引擎, 如javascript, 能够參考上篇博文.
4 调用jython解释器实现调用python代码文件
import org.python.util.PythonInterpreter intp = PythonInterpreter();
intp.exec('a = 5;')
intp.get('a');
但实际上exec方式与3中方法从功能上是一致的;
考虑到javacript engine的接口一致性,建议用3中方法.
Matlab中使用jython扩展功能的更多相关文章
- Matlab中imagesc用法
来源:https://ww2.mathworks.cn/help/matlab/ref/imagesc.html?searchHighlight=imagesc&s_tid=doc_srcht ...
- matlab中floor 朝负无穷大四舍五入
来源:https://ww2.mathworks.cn/help/matlab/ref/floor.html?searchHighlight=floor&s_tid=doc_srchtitle ...
- matlab中num2str 将数字转换为字符数组
参考:https://ww2.mathworks.cn/help/matlab/ref/num2str.html?searchHighlight=num2str&s_tid=doc_srcht ...
- matlab中imread 从图形文件读取图像
来源:https://ww2.mathworks.cn/help/matlab/ref/imread.html?searchHighlight=imread&s_tid=doc_srchtit ...
- matlab中bitshift 将位移动指定位数
来源:https://ww2.mathworks.cn/help/matlab/ref/bitshift.html?searchHighlight=bitshift&s_tid=doc_src ...
- matlab中reshape 重构数组
来源:https://ww2.mathworks.cn/help/matlab/ref/reshape.html?searchHighlight=reshape&s_tid=doc_srcht ...
- matlab中find 查找非零元素的索引和值
来源:https://ww2.mathworks.cn/help/matlab/ref/find.html?searchHighlight=find&s_tid=doc_srchtitle f ...
- matlab中fseek 移至文件中的指定位置
文章来源:https://ww2.mathworks.cn/help/matlab/ref/fseek.html?searchHighlight=fseek&s_tid=doc_srchtit ...
- matlab中for 用来重复指定次数的 for 循环
参考:https://ww2.mathworks.cn/help/matlab/ref/for.html?searchHighlight=for&s_tid=doc_srchtitle for ...
随机推荐
- (2)OLEDB数据库操作
1.首先要引入 System.Data.OracleClient.dll 2.引入命名空间 using System.Data.OleDb; OleDb类 https://msdn.microsof ...
- Sum of bit differences among all pairs
This article was found from Geeksforgeeks.org. Click here to see the original article. Given an inte ...
- Codeforces 920 E Connected Components?
Discription You are given an undirected graph consisting of n vertices and edges. Instead of giving ...
- 集合框架(上):学生选课(collection)
利用集合存储课程信息: 1.Course类 package com.collection; public class Course { public String id; public String ...
- 【译】PHP之道(PHP the right way)
刚入门的同学觉得自己能用PHP写出各种程序就很NB了,但其实作为一个专业程序员,你得有个全面点的知识结构.单元测试总得听过,文档工具总得用用,Xss总得会防.推荐大家把<PHP the righ ...
- Http标准协议Android网络框架——NoHttp
NoHttp详细文档:http://doc.nohttp.net NoHttp公益测试接口:http://api.nohttp.net 支持与RxJava完美结合.支持一句话切换底层为OkHttp,支 ...
- 设计模式之过滤器模式(php实现)
/** * github地址:https://github.com/ZQCard/design_pattern * 过滤器模式(Filter Pattern)或标准模式(Criteria Patter ...
- codeforces559A--Gerald's Hexagon(计算几何)
A. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Hive日期格式转换用法
如果想把 20180123 转换成 2018-01-23,可以使用: select from_unixtime(unix_timestamp('${p_date}','yyyymmdd'),'yyyy ...
- go语言25个关键字总结
var和const :变量和常量的声明var varName type 或者 varName : = valuepackage and import: 导入func: 用于定义函数和方法return ...