Assigning values in a shape in an array
3 ビュー (過去 30 日間)
古いコメントを表示
I have made an initial array, 161 x 161, of zeros:
x = (-80:80);
box = numel(x);
[X,Y] = meshgrid(x,x);
B = zeros([box, box]);
Then, I could make a circle in the array with value 10:
a = 10;
B(X.^2 + Y.^2 <= 100) = a;
However, I would like to make a semicircle of 'a' in the array, rather than the circle.
My code:
B(Y.^2<=abs(sqrt(100-X.^2))
However, this isn't giving me the correct shape.
What kind of things do I have to keep in mind to get the shapes I want?
Thanks.
2 件のコメント
Walter Roberson
2019 年 8 月 11 日
sqrt never returns a negative so the abs() only helps if 100-x^2 is negative in which case you are dealing with complex absolute value and the result comes out like sqrt(abs(100-x^2)). This is nothing like a semicircle.
You are also comparing the sqrt to y^2, so definitely not semicircle.
How do you want the semicircle to be oriented?
(Y>=0) & (X.^2 + Y.^2 <= 100)
For example.
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!