Loop plotting with different linewidth within same figure

19 ビュー (過去 30 日間)
Hampus Alfredsson
Hampus Alfredsson 2018 年 4 月 27 日
回答済み: Ameer Hamza 2018 年 4 月 27 日
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 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 4 月 27 日
What error are you getting?
Hampus Alfredsson
Hampus Alfredsson 2018 年 4 月 27 日
Value not a numeric scalar.

サインインしてコメントする。

回答 (1 件)

Ameer Hamza
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by