Set width of vector interval to plot.

조회 수: 4 (최근 30일)
Hampus Alfredsson
Hampus Alfredsson 2018년 2월 21일
댓글: Hampus Alfredsson 2018년 2월 22일
Hi!
I want to plot a vector where certain elements are somehow "better" and should be plotted as thicker lines. Still they should be the same line, only that it is thicker during some parts.

채택된 답변

Rik
Rik 2018년 2월 21일
I doubt this is possible with a single line object, but you can still do this. You can use the fact that plot will stop plotting at a NaN-value and resume when normal values occur again. So you can use your definition of better to replace the values that are worse with NaN. Then you just need to use hold(gca,'on') and plot again, with LineWidth set to a larger value.
  댓글 수: 7
Rik
Rik 2018년 2월 22일
So you are actually plotting a graph. There is a built-in that does that (since R2015b). You can even supply the weights for each edge. The example code below is from the graph.plot doc. The doc for the graph function itself can be found here.
s = [1 1 1 1 2 2 3 4 4 5 6];
t = [2 3 4 5 3 6 6 5 7 7 7];
weights = [50 10 20 80 90 90 30 20 100 40 60];
G = graph(s,t,weights)
LWidths = 5*G.Edges.Weight/max(G.Edges.Weight);
plot(G,'EdgeLabel',G.Edges.Weight,'LineWidth',LWidths)
The s and t vectors contain the starting node index and terminal node index for each edge (=line in your plot). The weight determines the thickness of each line.
Hope this helps. I don't think you have supplied enough information for me to provide an example with your data.
Hampus Alfredsson
Hampus Alfredsson 2018년 2월 22일
Thank you very much @Rik Wisselink

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by