Change dashed line spacing on plot

I need to plot 6 different black lines on plot, and all of them need to be lines (without markers). The problem is there are only 4 types of lines (- line, : dotted, -- dashed, -. dash dot) in Matlab plot. I did not find the possibility to change spacing in dashed line, or any other line. Is there some possibility for that, maybe in more recent versions of Matlab?
I found very usefyl script for dashed line but when I plot dot dash line with it, dots are too big, like markers. Does anyonw know how to get smaller dots in that script?

답변 (1개)

KSSV
KSSV 2019년 3월 15일

0 개 추천

You may follow something like this:
x = 1:100 ;
y = rand(size(x)) ;
% make dashed line with gaps
idx = reshape(x,10,[])' ; % this can be changed to skip lines accordingly
y(idx(1:2:end)) = NaN ;
plot(x,y,'--r')

댓글 수: 3

What is doing this line:
y(idx(1:2:end)) = NaN ;
Because in my case Matlab says
Subscript indices must either be real positive integers or logicals.
KSSV
KSSV 2019년 3월 15일
What version you are using? idx arranges indices in certain order.
I G
I G 2019년 3월 15일
I am using R2015a

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Labels and Styling에 대해 자세히 알아보기

제품

릴리스

R2015a

질문:

I G
2019년 3월 15일

댓글:

I G
2019년 3월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by