[TIP] Matlab에서 내가 원하는 간격에 맞춰 마커 찍기

2022. 9. 5. 04:39
728x90

오늘은 Matlab에서 마커를 주기적으로 찍는 방법에 대해 배워보자.

 

우선 Monte Carlo 기반 시뮬레이션의 결과에 대해 마커를 찍게되면, 정말 무수히 많은 마커가 생성되게 된다. 잘못된 것은 아니지만, 논문에 들어가기 위해서는 다소 깔끔하게 다듬을 필요성이 있다.

 

필자는 2가지 방법을 사용하고 있으며, 차근차근 살펴보도록 하자.

 

우선 X-axis의 값을 이용하여 찍는 방법이다. 해당 방법은 X, Y 축이 정수 단위일떄만 적용 가능하므로 추천하진 않는다.

% Marking by using specific values (can't apply the demical value)
% plot (1:2:numel(Xaxis), Reinforce_SE(1:2:end),'-*','LineWidth', 1.5,'MarkerSize', 7.5, 'color', '#c00000'); hold on
% plot (1:2:numel(Xaxis), Dqn_SE(1:2:end),'-s','LineWidth', 1.5, 'MarkerSize', 7.5, 'color', '#7f7f7f'); hold on
% plot (1:2:numel(Xaxis), Equal_SE(1:2:end),'-o','LineWidth', 1.5, 'MarkerSize', 7.5, 'color', '#bfbfbf'); hold on
% plot (1:2:numel(Xaxis), Maxprob_SE(1:2:end),'-d','LineWidth', 1.5, 'MarkerSize', 7.5, 'color', '#d9d9d9'); hold on

 

이때, 1:2:numbel(X)가 의미하는 것은 1부터 2씩의 간격으로 X가 종료될떄까지 순회하면서 마커를 찍는다는 의미를 지닌다. 또한 Y(1:2:end)역시 X축에서 설명한 바와 동일하다. 하지만 앞서 설명한 것 처럼 X 혹은 Y 축의 값이 정수형일떄만 적용이 가능하다. 코드 라인은 짧아져서 좋긴하지만, 데이터 유형에 따라 제약이 많이 존재하는 단점을 지닌다.

 

다음은 필자가 가장 많이 사용하는 방식인 인덱싱 기반의 마커 처리 방법이다.

해당 방안은 위에서 발생하는 문제를 해결하기 위해 고안한 방안이지만, 코드 라인이 Legend마다 하나씩 더 추가된다는 단점? 아닌 단점을 가진다.

% Marking by using specific indexs
p1 = plot (Xaxis, Reinforce_SE,'-*','LineWidth', 2.0, 'MarkerSize', 8.5, 'color', '#4453C0'); hold on 
p1.MarkerIndices = 1:2:length(Reinforce_SE);

p2 = plot (Xaxis, Dqn_SE,'-s','LineWidth', 2.0, 'MarkerSize', 7.5, 'color', '#00ADFA'); hold on 
p2.MarkerIndices = 1:2:length(Dqn_SE);

p3 = plot (Xaxis, Equal_SE,'-o','LineWidth', 2.0,'MarkerSize', 7.5, 'color', '#bfbfbf'); hold on
p3.MarkerIndices = 1:2:length(Equal_SE);

p4 = plot (Xaxis, Maxprob_SE,'-d','LineWidth', 2.0, 'MarkerSize', 7.5, 'color', '#7f7f7f'); hold on
p4.MarkerIndices = 1:2:length(Maxprob_SE);

 

728x90

BELATED ARTICLES

more