changing the way object are displayed (overloading openvar)

5 次查看(过去 30 天)
Hi,
I've implemented a class in which I overloaded many basic function likes size, subsref, etc.
The problem is that when I open the class in the variable panel it calls my size and subsref functions which are slow. I want it to return a massage like can't display an object of size > 10.
I tried to create a m file overload.m and to override the builtin openvar function so when called with my object it would behave as desired, otherwise it would call the builtin function. It didn't work, not sure why.
function openvar(varname)
if isa(varnmae, 'MultiField')
disp("can't display object");
else
builtin('openvar', varname);
end
end
And when I try to open any variable I get
Error using openvar
Too many input arguments.
  2 个评论
Yong-Joo Kwon
Yong-Joo Kwon 2020-6-10
编辑:Yong-Joo Kwon 2020-6-10
function openvar(varname, varargin)
if strcmp(varnmae, 'MultiField')
disp("can't display object");
else
evalin('caller', ['openvar ' varname]);
end
end
Walter Roberson
Walter Roberson 2020-6-10
openvar receives a variable name, and the poster wants to check whether the variable named is of specific type, not whether the variable itself has specific name.
evalin caller is going to resolve to the exact same openvar routine, since the user was operating in the context of the calling routine when they got to this function.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by