Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Construct an object given another object of that class

1 Ansicht (letzte 30 Tage)
Matthias Schabel
Matthias Schabel am 8 Apr. 2011
Geschlossen: MATLAB Answer Bot am 20 Aug. 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

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by