주요 콘텐츠

copy

객체로 구성된 배열을 클립보드에 복사

설명

copy(clipboard,objArray)는 배열 objArray의 객체를 클립보드에 복사합니다. 복사한 객체를 붙여넣으려면 pasteTo 함수를 사용하십시오.

예제

예제

모두 축소

상태를 그룹화하고 그 내용을 차트에 복사합니다. 상태, 상자 또는 그래픽 함수를 그룹화할 때 그룹화된 객체에 포함된 모든 객체를 비롯하여 이러한 객체 간의 모든 관계도 복사하여 붙여넣을 수 있습니다. 이 방법은 프로그래밍 방식으로 객체를 복사하여 붙여넣을 수 있는 가장 간단한 방법입니다. 상태가 그룹화되지 않은 경우 상태를 복사해도 그 내용이 복사되지 않습니다.

Stateflow chart with a hierarchy of states. The outer state is called A. It contains two inner states called A1 and A2.

모델을 열고 차트의 Stateflow.Chart 객체에 액세스합니다.

open_system("sfHierarchyAPIExample")
ch = find(sfroot,"-isa","Stateflow.Chart");

이름이 AStateflow.State 객체를 찾습니다.

sA = find(ch,"-isa","Stateflow.State",Name="A");

sAIsGrouped 속성을 true로 설정하여 상태 A와 그 내용을 그룹화합니다. 이 속성의 이전 설정을 저장하면 나중에 해당 설정으로 되돌릴 수 있습니다.

prevGrouping = sA.IsGrouped;
sA.IsGrouped = true;

상태 이름을 Copy_of_A로 변경합니다. 이전 이름을 저장하면 나중에 해당 이름으로 되돌릴 수 있습니다.

prevName = sA.Name;
newName = "Copy_of_"+prevName;
sA.Name = newName;

클립보드 객체에 액세스합니다.

cb = sfclipboard;

그룹화된 상태를 클립보드에 복사합니다.

copy(cb,sA);

상태 속성을 원래 설정으로 복원합니다.

sA.IsGrouped = prevGrouping;
sA.Name = prevName;

객체의 사본을 클립보드에서 차트로 붙여넣습니다.

pasteTo(cb,ch);

새로운 상태의 상태 속성을 조정합니다.

sNew = find(ch,"-isa","Stateflow.State",Name=newName);
sNew.Position = sA.Position + [400 0 0 0];
sNew.IsGrouped = prevGrouping;

Chart showing result of pasting a copy of state A and its contents.

차트에서 상태 A1A2를 두 상태 간의 천이와 함께 새 상태로 복사합니다. 객체 간의 천이 연결과 포함 관계를 유지하려면 연결된 모든 객체를 한 번에 복사합니다.

Stateflow chart with a hierarchy of states. The outer state is called A. It contains two inner states called A1 and A2.

모델을 열고 차트의 Stateflow.Chart 객체에 액세스합니다.

open_system("sfHierarchyAPIExample")
ch = find(sfroot,"-isa","Stateflow.Chart");

이름이 AStateflow.State 객체를 찾습니다.

sA = find(ch,"-isa","Stateflow.State",Name="A");

이름이 B인 새 상태를 추가합니다. B의 내부에 다른 객체 붙여넣기를 활성화하기 위해 새 상태를 서브차트로 변환합니다.

sB = Stateflow.State(ch);
sB.Name = "B";
sB.Position = sA.Position + [400 0 0 0];
sB.IsSubchart = true;

상태 A의 상태와 천이 상태가 포함된 objArray라는 배열을 만듭니다. 복사할 객체 배열에서 상태 A를 제거하려면 setdiff 함수를 사용하십시오.

objArrayS = find(sA,"-isa","Stateflow.State");
objArrayS = setdiff(objArrayS,sA);
objArrayT = find(sA,"-isa","Stateflow.Transition");
objArray = [objArrayS objArrayT];

클립보드 객체에 액세스합니다.

cb = sfclipboard;

objArray의 객체를 복사하여 서브차트 B에 붙여넣습니다.

copy(cb,objArray);
pasteTo(cb,sB);

B를 이전 상태로 되돌립니다.

sB.IsSubchart = false;
Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.Transition' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.Transition' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.State' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: Assertion failed:  Deviant 'root deviant' not opened for transactions.
Attempt to modify object of type 'StateflowDI.State' [id = -1 ]  at kernel/deviant/Deviant.cpp:70: 
sB.IsGrouped = false;

B의 상태와 천이를 재배치합니다.

newStates = find(sB,"-isa","Stateflow.State");
newStates = setdiff(newStates,sB);

newTransitions = find(sB,"-isa","Stateflow.Transition");
newOClocks = get(newTransitions,{"SourceOClock","DestinationOClock"});

for i = 1:numel(newStates)
    newStates(i).Position = newStates(i).Position + [25 35 0 0];
end
set(newTransitions,{"SourceOClock","DestinationOClock"},newOClocks);

Chart showing result of copying contents of state A and pasting them into state B.

입력 인수

모두 축소

클립보드로, Stateflow.Clipboard 객체로 지정됩니다.

복사할 객체로, Stateflow API 객체로 구성된 배열로 지정됩니다. 배열에는 그래픽 객체만 또는 비그래픽 객체만 포함되어야 합니다.

그래픽 객체에는 다음이 포함됩니다.

비그래픽 객체에는 다음이 포함됩니다.

그래픽 객체를 복사하면 그래픽 객체에 포함된 Stateflow.Data 객체, Stateflow.Event 객체, Stateflow.Message 객체도 복사됩니다. 여러 그래픽 객체를 복사하는 경우 Subviewer 속성의 값이 같아야 합니다.

복사한 객체 간의 천이 연결과 포함 관계를 유지하려면 다음을 수행해야 합니다.

  • 그룹화된 객체를 클립보드에 복사하십시오. 상태, 상자 또는 그래픽 함수를 그룹화할 때 그룹화된 객체에 포함된 모든 객체를 비롯하여 이러한 객체 간의 모든 관계도 복사하여 붙여넣을 수 있습니다. 자세한 내용은 그룹화를 통해 복사하여 붙여넣기 항목을 참조하십시오.

  • 모든 관련 객체를 복사하십시오. 예를 들어, 천이에 의해 연결된 두 개의 상태를 다른 컨테이너로 복사하려면 상태와 천이가 모두 포함된 배열을 만듭니다. 그런 다음 배열을 클립보드에 복사할 수 있습니다. 자세한 내용은 객체의 배열 복사 및 붙여넣기 항목을 참조하십시오.

버전 내역

R2006a 이전에 개발됨