Loop plotting with different linewidth within same figure
조회 수: 20 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Ameer Hamza
2018년 4월 27일
'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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!