Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Construct an object given another object of that class

1 visualización (últimos 30 días)
Matthias Schabel
Matthias Schabel el 8 de Abr. de 2011
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
What I want to do can be accomplished with the following :
classdef X methods function obj = X(x) obj.x = x; end
function y = f(obj,x)
y = eval([class(x) '(' num2str(-x.x) ')']);
end
end
properties
x;
end
end
a = X(2); b = a.f(a);
but the use of eval is ugly and slow. Is there not a better way to get the class of an object from the object itself?
Matthias

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by