Is it possible to create a shortcut for a function?
13 次查看(过去 30 天)
显示 更早的评论
I use Yalmip to achieve optimization. And when debugging, I use value() function a lot to see the value of the variables. But it is tedious and unefficent. I have to input in the command window value() and then copy the variable in the code, and then paste it. So I wanna if there is a way that I can create a shortcut for the function value(), so that everytime I want to see the value I just select the content that I need and click the shortcut and then things appear in the command window.
0 个评论
回答(1 个)
Keshav
2023-7-31
In MATLAB, it is not possible to create a custom shortcut for your task directly. However, you can write your own script to simplify the task. By creating a script, you can automate the process of applying the 'value' function to the selected item and printing the result. Once you have the script, you can easily see the value by selecting the content and running the script.
You can refer to the following script, which applies the 'value' function to the copied text and displays the output:
% Get the selected content
selectedContent = clipboard('paste');
% Evaluate the selected content using the value() function
result = evalin('base', ['values(', selectedContent, ')'])
By using this script, you can simply copy the desired content and run the script (by entering script file name in the command window) to see the corresponding value.
You can read more about ‘evalin’ function in the below MathWorks documentation.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!