Plotting multipe lines with different width

7 visualizaciones (últimos 30 días)
Tchilabalo
Tchilabalo el 29 de Sept. de 2019
Editada: dpb el 29 de Sept. de 2019
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

Respuesta aceptada

dpb
dpb el 29 de Sept. de 2019
Editada: dpb el 29 de Sept. de 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...

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by