Matlab毒药和数字
3 Matlab 问题
1 - 有谁知道在 matlab 中是否有等价的
#pragma GCC poison variable_name
,即如果发现从此时开始在代码中使用了variable_name,它会导致 matlab 出错?
另外两个不太相关的问题,因为我仍然不敢相信。
执行操作之外,是否有任何方法可以将命令链接
imagesc(I1_avg_crop, [bg_value multiplier2*std_value+bg_value]);
到特定的图形
set(0,'CurrentFigure',fig3);
imagesc(I1_avg_crop, [bg_value multiplier2*std_value+bg_value]);
2 - 除了在它之前
? 3 - getframe() (或类似的)实际上可以获取图形中的内容而不是“进行屏幕捕获”吗?因为当移动图形窗口时它不能很好地工作?
(我正在编辑某人的代码,而且我是 matlab 新手,所以如果这些是愚蠢的问题,我提前道歉,只是我无法在文档中找到我想要的内容)
编辑:额外问题 手册说
set(0,'CurrentFigure',h);
使图形 h 当前,但不改变其可见性或相对于其他图形的堆叠。这是否仍然适用于 Mac OS X,因为它似乎仍然将其强制置于顶部?
3 Matlab questions
1 - Does anyone know if there is an equivalent to
#pragma GCC poison variable_name
in matlab, i.e. it causes matlab to error if it finds variable_name being used from this point onwards in the code?
Two other less related questions, as i still can't believe it.
2 - Is there anyway to link commands like
imagesc(I1_avg_crop, [bg_value multiplier2*std_value+bg_value]);
to a figure in particular, other than doing
set(0,'CurrentFigure',fig3);
imagesc(I1_avg_crop, [bg_value multiplier2*std_value+bg_value]);
immediately before it?
3 - can getframe() (or similar) actually get whats in a figure rather than "doing a screen capture"?, as it doesn't work so well when the figure window is moved?
(I'm editing someones code, and i am new to matlab, so i apologise in advance if these are stupid questions, its just i can't locate what i want in the documentation)
EDIT: Extra Question
The manual says
set(0,'CurrentFigure',h);
Makes the figure h current, but do not change its visibility or stacking with respect to other figures. Does this still apply on Mac OS X as it seems to still force it to the top?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(1) 不,不可能“本地”毒害变量。但是,您可以执行以下解决方法:定义一个这样的类:
然后您可以调用
variable_name =poison('variable_name')
并获得相同的效果 - 如果variable_name
为覆盖时,它会触发对象的删除方法并抛出错误,如果尝试索引或算术操作,则会出现一般错误。(2) 您可以在函数调用中显式设置图像的父级(传递一个轴句柄,例如可以通过 axHandle =axes('Parent',fig3); 获取该句柄),从而避免调用该图。但是,您不能执行此操作并设置颜色图缩放。因此,您必须使用
,或者,如果您无法访问图像处理工具箱,则需要使用
image
(3) 如果您使用
getframe
调用轴句柄,它应该能够捕获轴的内容 - 除非您将图形移动到第二个屏幕上,在这种情况下它将不起作用。顺便说一句:我注意到getframe
过去在 OSX 上有问题,例如对接数字。(4) 有时 Matlab 会出现特定于 OSX 的问题,因为他们仍在调试一些非常基本的东西(OSX 版本曾经是在 X-Windows 中运行的 Linux 版本,他们一直在努力改变过去几年的情况)。
(1) No, it isn't possible to "natively" poison a variable. However, you can do the following workaround: Define a class like this:
Then you can call
variable_name = poison('variable_name')
and get the same effect - ifvariable_name
is overwritten, it triggers the object's delete method and throws an error, if there is an attempt at indexing, or at arithmetic manipulation, there are generic errors.(2) You can set the parent of the image explicitly (pass an axes handle, which you can e.g. obtain by
axHandle = axes('Parent',fig3);
) in the function call, which avoids calling the figure. However, you cannot do that and set colormap scaling. Thus, you have to either useor, if you don't have acces to the image processing toolbox, you need to use
image
(3) If you call
getframe
with an axes handle, it should be able to capture the contents of the axes - unless you moved the figure onto the second screen, in which case it won't work. BTW: I have noticedgetframe
to have issues on OSX in the past, e.g. with docked figures.(4) There are, at times OSX-specific issues with Matlab, as they are still debugging some of the very basic stuff (the OSX version used to be the Linux version running in X-Windows, and they've been working on changing that for the last few years).
第(3 和 4)点是因为我使用 getframe 来获取图像,这迫使窗口被带到前面,因此它可以对其进行屏幕截图。我现在通过使用 http://www.mathworks.com 找到了解决方案/help/techdoc/ref/avifile.addframe.html 远远优于 getframe,因为它可以采用“图形或轴句柄 h”。
关闭它很重要,否则它不会保存图像。显然也没有遇到屏幕保护程序问题。
Point (3 & 4) was because i was using getframe to get an image and this forced the window to be brought to the frount, so it could do a screenshot of it. I have now found a solution by using http://www.mathworks.com/help/techdoc/ref/avifile.addframe.html which is far superior to getframe as it can can take a "figure or axis handle h".
its important to close it, as otherwise it doesn't save the image. Also apparently doesn't suffer from the screensaver problem.