Question regarding making a certain shape on a grid in mat lab

2 ビュー (過去 30 日間)
Edward Villanueva
Edward Villanueva 2020 年 3 月 11 日
編集済み: Ameer Hamza 2020 年 3 月 11 日
I am having trouble figuring out how to create a shape on a grid. In my case I would like to create two L shapes side by side. however I dont know how exactly I would go about filling those shapes on a grid so that I may plot it. Would it require me making a matrix of points on the grid? And if so how would I know those points if I were to make my grid abnormaly large, like 10000x10000.
  1 件のコメント
Edward Villanueva
Edward Villanueva 2020 年 3 月 11 日
I guess im asking how I would create shapes on a predefined grid, in this case two L shapes side by side facing opposite from one another

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 11 日
編集済み: Ameer Hamza 2020 年 3 月 11 日
If you treat the grid as image and point on grid as image pixels, then you can use insertText function to put text on the grid. For example
[x, y] = meshgrid(1:500, 1:500);
z = ones(size(x));
z = insertText(z, [150 250; 350 250], {'L', 'L'}, ...
'FontSize', 200, ...
'BoxColor', [1 1 1], ...
'AnchorPoint', 'Center');
z = imbinarize(rgb2gray(z));
imshow(imresize(z, [10000, 10000]))
  2 件のコメント
Edward Villanueva
Edward Villanueva 2020 年 3 月 11 日
I appreciate this answer, but I was looking more for a way to create two L's that are facing opposite of one another. In addition I would like to perform mathimatical operations on these points.
Ameer Hamza
Ameer Hamza 2020 年 3 月 11 日
編集済み: Ameer Hamza 2020 年 3 月 11 日
If you want the opposite facing L, then you can try the following code.
[x, y] = meshgrid(1:500, 1:500);
z = ones(size(x));
z = insertText(z, [150 250], {'L'}, ...
'FontSize', 200, ...
'BoxColor', [1 1 1], ...
'AnchorPoint', 'Center');
z = imbinarize(rgb2gray(z));
z = z.*fliplr(z);
imshow(imresize(z, [10000, 10000]))
Note, images are also matrices in MATLAB. So you can do any mathematical operation on them. For example, I used the function fliplr, which is used to flip a matrix, and then I multiplied it with the original matrix.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by