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!