Loop plotting with different linewidth within same figure
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ameer Hamza
am 27 Apr. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!