필터 지우기
필터 지우기

How to refer to workspace variable in Matlab toolbar shortcut?

조회 수: 1 (최근 30일)
Wojciech Krauze
Wojciech Krauze 2015년 11월 23일
댓글: Wojciech Krauze 2015년 11월 30일
I would like to create a new toolbar shortcut that would perform some simple operation on a variable marked with a mouse in a workspace. I already have a shortcut for imagesc taken from available Matlab shortcuts. When I click on a variable and then click on the imagesc shortcut, the variable is displayed. This shortcut knows which variable to display. So my question is: what argument should I give in a script for new shortcut to pick the variable that is "clicked" in a workspace.

채택된 답변

Jan
Jan 2015년 11월 29일
jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
jWSBrowser = jDesktop.getClient('Workspace');
WSTable = jWSBrowser.getComponent(0).getComponent(0).getComponent(0);
selectedRows = WSTable.getSelectedRows;
selectedVars = cell(1, numel(selectedRows));
for k = 1:numel(selectedRows)
selectedVars{k} = WSTable.getValueAt(selectedRows(k),0);
end

추가 답변 (1개)

Jan
Jan 2015년 11월 23일
Where is the variables marked? In the command window or the editor?
activeEditor = matlab.desktop.editor.getActive;
currentSelection = activeEditor.SelectedText;
Yair suggested this for the command window:
%# 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)
  댓글 수: 2
Wojciech Krauze
Wojciech Krauze 2015년 11월 23일
The variable is marked in the Workspace window. Where all current variables are shown.
Wojciech Krauze
Wojciech Krauze 2015년 11월 25일
Jan, thank you for your answer but do you know a method to refer to the variable "clicked" in the Workspace window (not Command Windows or Editor)?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by