Loop plotting with different linewidth within same figure
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
2 commentaires
Réponses (1)
Ameer Hamza
le 27 Avr 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
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!