Plotting multipe lines with different width
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
dpb
le 29 Sep 2019
Modifié(e) : dpb
le 29 Sep 2019
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...
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!