Plotting multipe lines with different width
조회 수: 3 (최근 30일)
이전 댓글 표시
I have 5000 lines with their endpoints coordinnates. I want to plot all these lines in one figure, but each line will have a different width. With a for loop (see code), it is taking forever to execute. Ia m wondering if there is a better way to do this. Thanks.
A =[X1(:) X2(:)].'; B =[Y1(:) Y2(:)].';% Line endpoints
width=round((width*5)/(max(width)))% Vector giving each line thickness
figure;hold on
for i=1:length(A);
plot(A,B,'LineWidth',width(i));
end
grid on
댓글 수: 0
채택된 답변
dpb
2019년 9월 29일
편집: dpb
2019년 9월 29일
Firstly, your time problem is that your A and B are the vectors of all points and you're plotting the whole thing every time by referencing the arrays without subscripting. So you have length(A)^2 lines instead of just length(A).
A =[X1(:) X2(:)].'; B =[Y1(:) Y2(:)].';
w=round((width*5)/(max(width))); % width isn't defined here on RHS????
figure
hL=plot(A,B); % plot array by column, save line handle array
set(hL,{'LineWidth'},num2cell(w(:))) % set line widths for all handles from w array
As noted, there needs be a definition of the variable width on RHS of the above...
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!