Hello. I would like to convert this figure on the left to a 64 by 64 grid matrix. In the matrix, I want all values to be zero except the values that align with the red circles. Those values should be 1. Is this possible in matlab?

回答 (1 件)

David Hill
David Hill 2021 年 4 月 1 日

0 投票

[x,y]=meshgrid(linspace(-2,2,64));
z=zeros(size(x));
k=x.^2+y.^2;
z(k<=1)=1;%z is the grid matrix

2 件のコメント

Nne Akallu
Nne Akallu 2021 年 4 月 1 日
Hello. Thank you. Please can you explain the code? I'm new to matlab :)
David Hill
David Hill 2021 年 4 月 1 日
meshgrid just creates all the possiblities for x and y in 64x64 matrix
computing k is just the equation of a circle using element-wise operations of the x and y matrices
zeros() just initially sets the z (answer) matrix to all zeros
z(k<=1) is logical indexing into z where k<=1 and setting all of those positions to 1

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

カテゴリ

ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索

タグ

質問済み:

2021 年 4 月 1 日

コメント済み:

2021 年 4 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by