필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Construct an object given another object of that class

조회 수: 1 (최근 30일)
Matthias Schabel
Matthias Schabel 2011년 4월 8일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by