MATLAB: How to refer to workspace variable in Matlab toolbar shortcut

argumentstoolbar shortcut

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.

Best Answer

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
Related Question