MATLAB显示工作区元素的链接 [英] MATLAB display a link to workspace elements
问题描述
我正在尝试提高输出的可读性.为了避免显示大量数据,最好显示指向工作空间中特定元素(即变量,表格,图形等)的链接.
I'm trying to improve the readability of my outputs. In order to avoid displaying a lot of data, it would be nice to display links that point to specific elements in the workspace (i.e. a variable, a table, a figure, etc.).
下面是一张图片来说明这个想法:
Here is a picture to illustrate the idea:
也许我们可以使用disp
函数,因为我知道它可以生成指向网页或存储在计算机中的文件的超链接.
Maybe we can use the disp
function, as I know it allows the generation of hyperlinks to a webpage or a file stored in the computer.
在MATLAB中有可能吗?
Is this possible in MATLAB?
推荐答案
好的,这就是我的想法.首先是使用 openvar
函数,然后指定要用单引号引起来的变量.这将在变量编辑器"(快照中显示的图像)中打开变量.
OK, so this is what I came up with. The first thing is to use the openvar
function and you specify the variable you want wrapped around in single quotations. This will open up the variable in the Variable Editor (the image that is pictured in your snapshot).
现在,您还可以使用disp
允许可点击的链接运行MATLAB命令.使用这两个想法,可以将disp
链接和openvar
组合在一起,以允许可单击的链接执行openvar
函数以显示所需的变量.
Now, you can also use disp
to allow clickable links to run MATLAB commands. Using these two ideas, you would combine the disp
linking and openvar
to allow a clickable link to execute the openvar
function to display your desired variable.
这样,您基本上会假设我们的变量存储在A
中:
As such, you would basically do this assuming our variable is stored in A
:
A = magic(5);
disp('<a href="matlab:openvar(''A'')">Click on me to show the matrix A</a>')
disp
语句将为您显示一个可单击的链接,并且只有在您单击链接后才能运行所需的要执行的功能.您可以通过在href
键的URL中指定matlab:
关键字来实现此期望的效果,然后在其后写出要使用的任何MATLAB函数或语句.在我们的例子中,我们只需要运行一个函数,那就是openvar
.确保在openvar
的参数内要在变量周围指定单引号.原因是因为disp
的参数是一个字符串,并且如果要识别单引号,则必须使用一对单引号.这样,在disp
字符串中,您想要的变量周围有一对单引号.
The disp
statement will show you a clickable link, and the desired function to be executed only runs if you click on the link. You can achieve this desired effect by specifying the matlab:
keyword inside the URL in the href
key, then after it, you write out whatever MATLAB function or statements you want to use. In our case, we use only need to run one function, and that's openvar
. Make sure you specify single quotes around the variable you want inside the argument to openvar
. The reason why is because the argument to disp
is a string, and if you want single quotations to be recognized, you must use a pair of single quotes. As such, in the disp
string, there are pairs of single quotes around the variable you want.
这是我在MATLAB中得到的.复制这些步骤并以GIF动画形式对其进行显示:
Here's the what I get in MATLAB. The steps are reproduced and shown in an animated GIF:
这篇关于MATLAB显示工作区元素的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!