Effacer les filtres
Effacer les filtres

changing the way object are displayed (overloading openvar)

2 vues (au cours des 30 derniers jours)
Or Nahir
Or Nahir le 8 Juil 2018
Commenté : Walter Roberson le 10 Juin 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 commentaires
Yong-Joo Kwon
Yong-Joo Kwon le 10 Juin 2020
Modifié(e) : Yong-Joo Kwon le 10 Juin 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 le 10 Juin 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by