Loop plotting with different linewidth within same figure

22 visualizaciones (últimos 30 días)
Hampus Alfredsson
Hampus Alfredsson el 27 de Abr. de 2018
Respondida: Ameer Hamza el 27 de Abr. de 2018
I have three 3D matrices(A,B and C) of same size but different values. I want to plot them all in one figure as layers upon each other. Though I want the linewidth to be set specifically for every value being plotted. The code below works fine as long as I define the linewidth myself, but I want it to vary in the figure. Please help.
figure
hold on
for ii = 1:size(A,3)
plot(A(:,2,ii),A(:,1,ii),'-black');
plot(B(:,2,ii),B(:,1,ii),'-r','LineWidth',B(:,3,ii));
plot(C(:,2,ii),C(:,1,ii),'og','LineWidth',C(:,3,ii));
end
hold off

Respuestas (1)

Ameer Hamza
Ameer Hamza el 27 de Abr. de 2018
'LineWidth' option just accept single number, whereas, in your code, you are passing an array B(:,3,ii) to it. To solve this problem separately define vectors of the width of lines as follow
widthLine2 = 1:size(A,3); % just an example, you can change it according to thickness you want
widthLine3 = 1:size(A,3); % just an example, you can change it according to thickness you want
figure
hold on
for ii = 1:size(A,3)
plot(A(:,2,ii),A(:,1,ii),'-black');
plot(B(:,2,ii),B(:,1,ii),'-r','LineWidth', widthLine2(ii));
plot(C(:,2,ii),C(:,1,ii),'og','LineWidth', widthLine3(ii));
end
hold off

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by