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
Question regarding making a certain shape on a grid in mat lab
2 ビュー (過去 30 日間)
古いコメントを表示
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 件)
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 件のコメント
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!