Assigning values in a shape in an array
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Shashvat Verma
il 11 Ago 2019
Risposto: Shashvat Verma
il 11 Ago 2019
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 Commenti
Walter Roberson
il 11 Ago 2019
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.
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!