Eric
Eric

Reputation: 97591

How can I copy a graphical object and change its properties before inserting it?

Say I have a simple plot:

f = figure;
line = plot([1, 2, 3], [1, 4, 9]);

I can make a copy of the line with copyobj, and change some properties:

line2 = copyobj(line, line.Parent);
set(line2, 'SomeProp', ...);

Is there any way to modify the properties after the copy, but before setting the .Parent?

Upvotes: 1

Views: 32

Answers (1)

Eric
Eric

Reputation: 97591

It seems that passing a string into copyobj trick it into not setting the parent:

line2 = copyobj(line, 'tricked you');
assert(isempty(line2.Parent));
set(line2, 'SomeProp', ...);
line2.Parent = line.Parent;

I can't find any documentation for why this isn't just an error though

Upvotes: 1

Related Questions