Using regexp to parse plot's LineSpec
이전 댓글 표시
Hello, I'm trying to parse the LineSpec string used in plot(...,LineSpec).
LineSpec specifies the plot line's style/marker/color, for example "-or". Some of the possible options are:
- Style: - | -- | .- | -. | :
- Marker: [o+*._|sd^v><]
- Color: [rgbcymkw]
So far I had some success in regexp with
regexp(str,'((-[-|.]?)|:|(.-))?+[o+*._|sd^v><]?+[rgbcymkw]?','match','once')
and
regexp(str,'^(?:([rgbcymkw.:-*sodv^><][^.]*)(?!.*\1))+$','match','once')
or by splitting and erasing the string at each stage (not an elegant solution). However, this method parses also words, is not strict against repetitions and fails by changing the order.
I am trying to split a LineSpec into its three components, but just having regexp recognize a string as a valid LineSpec would be great. Would it possible to do this with a regexp pattern?
Thank you in advance.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!