카테고리
Package Drillpackage-drill
코드와 해설을 함께 읽는 학습 문서
Code Detail
Control & Dynamics + Visualization 중심의 Octave 학습 예제
ex-pkg/ex-cms.m
코드를 복사해 Octave에서 바로 실행할 수 있습니다.
function [color, marker, linestyle] = extract_plot_style(style)
33 lines
function [color, marker, linestyle] = extract_plot_style(style)
% 색상 패턴
color_pattern = '[bgrcmykw]';
% 마커 패턴
marker_pattern = '[\.\+ox\*sdv\^<>ph]';
% 라인 스타일 패턴
linestyle_pattern = '(-{1,2}|:|-\.)';
% 색상 찾기 (첫 번째 매칭)
color_match = regexp(style, color_pattern, "match", "once");
% 라인 스타일 찾기 (첫 번째 매칭)
linestyle_match = regexp(style, linestyle_pattern, "match", "once");
% 마커 찾기 (첫 번째 매칭)
marker_match = regexp(style, marker_pattern, "match", "once");
% 결과 반환 (없으면 빈 문자열)
color = ifelse(isempty(color_match), "", color_match);
marker = ifelse(isempty(marker_match), "", marker_match);
linestyle = ifelse(isempty(linestyle_match), "", linestyle_match);
end
% 예제 실행
test_set = {"ro-", "b--", "g*", "k:"};
for i = 1:size(test_set, 2)
test = test_set{i};
[color, marker, linestyle] = extract_plot_style(test);
printf(fmt("Test: {test}, Color: {color}, Marker: {marker}, LineStyle: {linestyle}\n"))
end ex-pkg/ex-control.m
ex-pkg/ex-fmt.m
ex-pkg/ex-fstring.m
ex-pkg/ex-image.m
ex-pkg/ex-io.m
ex-pkg/ex-optim.m
ex-pkg/ex-signal.m
ex-pkg/ex-statistics.m