如何在MATLAB中检索选定的文本? [英] How do you retrieve the selected text in MATLAB?

查看:112
本文介绍了如何在MATLAB中检索选定的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MATLAB具有几种对选择敏感的功能.例如,如果您选择一些文本并按F9,它将评估您的选择. (除非您重新映射了键盘设置.)

MATLAB has several selection-sensitive capabilities. For example, if you select some text and press F9, it evaluates your selection. (Unless you've remapped your keyboard settings.)

我希望能够通过快捷方式复制此功能.因此,例如,我想单击显示当前选择的快捷方式.我的快捷方式回调为disp(GetSelection()).

I'd like to be able to replicate this functionality with for a shortcut. So, for example, I want to click a shortcut that displays the current selection. My shortcut callback would be disp(GetSelection()).

但是GetSelection中有什么?

推荐答案

感谢 @Yair Altman 未记录的Matlab ,我能够找出要执行以下操作的Java命令:使这项工作.

Thanks to @Yair Altman's undocumented Matlab, I was able to figure out the java commands to make this work.

将其放在快捷方式(或由快捷方式调用的函数)中:

Put this in a shortcut (or a function that is called by the shortcut):

%# find the text area in the command window
jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
try
  cmdWin = jDesktop.getClient('Command Window');
  jTextArea = cmdWin.getComponent(0).getViewport.getComponent(0);
catch
  commandwindow;
  jTextArea = jDesktop.getMainFrame.getFocusOwner;
end

%# read the current selection
jTxt = jTextArea.getSelectedText;

%# turn into Matlab text
currentSelection = jTxt.toCharArray'; %'

%# display
disp(currentSelection)

这篇关于如何在MATLAB中检索选定的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆