How to insert grid lines specific position ?

How to insert grid lines specific position ? check this attached Imafe? How to insert grid line inside red line box on image?

2 件のコメント

darova
darova 2019 年 8 月 20 日
You can use plot
plot([800 1000] ,[600 250],'--g')
Or you want insert line into image?
Adam Danz
Adam Danz 2019 年 8 月 20 日
@darova , that plots a diagonal line.

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

 採用された回答

Adam Danz
Adam Danz 2019 年 8 月 20 日

0 投票

Here's a demo
% Define bound
%bound(1) is the x value of the bottom, left corner of the frame
%bound(2) is the y value for the same corner
%bound(3) is the width of the frame
%bound(4) is the height of the frame
bound = [.2 .1 .5 .7];
% Define grid
x = .3:.1:.6;
y = .2:.1:.7;
% Plot
cla()
xlim([0,1])
ylim([0,1])
hold on
rectangle('position', bound, 'EdgeColor','r')
% Plot vertical lines
vh = plot([x(:),x(:)],[bound(2),sum(bound([2,4]))], 'Color', [.6,.6,.6]);
% Plot horizontal lines
hh = plot([bound(1),sum(bound([1,3]))],[y(:),y(:)], 'Color', [.6,.6,.6])
190820 174130-Figure 1.jpg

6 件のコメント

voxey
voxey 2019 年 8 月 21 日
Thank you Adam Danz, also how to place x and y scale in near grid location ?
Adam Danz
Adam Danz 2019 年 8 月 21 日
Sorry, I didn't understand this question. What do you mean "near grid location"? And by "x and y scale" do you mean the intervals with in the grid or do you mean the scaling of each axis?
voxey
voxey 2019 年 8 月 21 日
Please check this image.
Adam Danz
Adam Danz 2019 年 8 月 21 日
編集済み: Adam Danz 2019 年 8 月 21 日
In my answer, these two lines define the placement of the grid line.
% Define grid
x = .3:.1:.6;
y = .2:.1:.7;
Assuming the image is placed in an axis where the bottom left corner of the axis is (0,0) and the top right corner is (7,9) (rough estimate from your drawing), then you can define the grid lines like this:
interval = 1; %distance between grid lines.
x = linspace(0,7,interval);
y = linspace(0,9,interval);
Give it a try. If you get stuck, share an image (or code) from the actual plot you're working with instead of a drawing.
voxey
voxey 2019 年 8 月 22 日
its not working? can you share sample result with this code?
Adam Danz
Adam Danz 2019 年 8 月 22 日
My answer contains a fully functional sample with this code.
What's not working? What problems are you having? As I mentioned, if you get stuck, share the relevant sections of code (only the relvant sections that plot the grid). And carefully explain what's not working.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2019 年 8 月 20 日

コメント済み:

2019 年 8 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by