【发布时间】:2013-01-28 21:35:05
【问题描述】:
我观察到在 Matlab 函数和命令窗口中运行相同代码时出现奇怪的行为。 How does scoping in Matlab work? 中已经描述了它,但我不明白如何解决我的具体问题。 代码如下:
exporteddata.m %File created by an external program
%to export data in Matlab format
surface = struct('vertices', [...]) ;
%I can't specify in the external program
%the name of the variable, it's always "surface"
我的实际代码是:
myfunction.m
function output = myfunction(input)
load(input);
n = size(surface.vertices);
....
运行时
myfunction('exporteddata.m');
我收到以下错误:
???类 hg.surface 没有合适的方法、属性或字段顶点。
在命令窗口或调试模式下运行相同的指令时,代码运行良好。
如何在函数中指定我需要工作区中存在的变量表面,而不是 Matlab 函数?
【问题讨论】:
标签: matlab overloading scope