Borrar filtros
Borrar filtros

changing the way object are displayed (overloading openvar)

2 visualizaciones (últimos 30 días)
Or Nahir
Or Nahir el 8 de Jul. de 2018
Comentada: Walter Roberson el 10 de Jun. de 2020
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 comentarios
Yong-Joo Kwon
Yong-Joo Kwon el 10 de Jun. de 2020
Editada: Yong-Joo Kwon el 10 de Jun. de 2020
function openvar(varname, varargin)
if strcmp(varnmae, 'MultiField')
disp("can't display object");
else
evalin('caller', ['openvar ' varname]);
end
end
Walter Roberson
Walter Roberson el 10 de Jun. de 2020
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by