How to Insert a Dotted Line using InsertShape?
13 ビュー (過去 30 日間)
古いコメントを表示
Hello. I'm trying to insert a dotted line onto my figure (A) but struggling with the line spec. Here is my line of code. Normally I'll put 'k--' or 'LineSpec','--' but error says "'LineSpec' is not a recognized parameter". Please can you help me?? Thank you, Sally
A = insertShape(A,'line',[1 168.5 301 168.5],'Color','black','LineWidth',6)
0 件のコメント
回答 (2 件)
Abhisek Pradhan
2019 年 7 月 16 日
The insertShape MATLAB function doesn’t have the functionality to insert a dotted line over a picture.
You can try a workaround mentioned below.
imshow(A);
hold on;
line([1,301],[168.5,168.5],'Color','r','LineStyle','--','LineWidth',6);
Wei Huang
2023 年 11 月 8 日
編集済み: Wei Huang
2023 年 11 月 8 日
Here is a way you can do this by interpolating between the points of your solid line:
% Create some image
I = uint8(zeros(400,400));
% Points defining solid line
solidLine = [1 168.5 301 168.5];
% Interpolating solid line to with n number of points
n = 20;
dashLine = [linspace(solidLine(1),solidLine(3),n);...
linspace(solidLine(2),solidLine(4),n)];
% Account for odd number of interpolated points
if mod(n,2)
n = n-1;
dashLine = dashLine(:,1:end-1);
end
% Reshape dash line for insertShape
dashLine = reshape(dashLine,4,n/2)';
I = insertShape(I,"line",dashLine,'Color','r','LineWidth',6);
imshow(I);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!