understanding "<" operator line
Mostrar comentarios más antiguos
Hello,I cant understand a line of the line bellow taken from the code bellow.
I think i generates a circle but i cant see how .
When i tried to use "<" operator it ony gave me true or false
Could you please give me simple example of using this principle of the line bellow?
midCirc= X.^2+Y.^2<(1/n)^2;
Thanks.
n=1024;% matix dimmensions
lambda=633e-9;% wave length in [m]
L=0.01;% meter factor, it is defined that 1cm=1024 pixels-> the first scale will be over 1cm
scale=linspace(-L/2,L/2,n);% basic scaling vector in length of 1024.
%% Q2 creating matrix
[X, Y]= meshgrid(scale,scale);% creating the basic function. on the function we will create the images that will operated
midCirc= X.^2+Y.^2<(1/n)^2;%because we work in meter units, the 100/1024[cm] transforms into 1/1024[m]
NmidCirc=not(midCirc);
Ring= ((X-0.8/n).^2+(Y-0.8/n).^2<(1/n)^2)&((X-0.8/n).^2+(Y-0.8/n).^2>(0.6/n)^2);
NRing=not(Ring);
Tshape= (abs(Y)<0.2/n)&(abs(X)<0.6/n) | ((Y<1.4/n)&(Y>0.2/n)&(abs(X)<0.2/n));
NTshape=not(Tshape);
figure(100)
colormap gray;
Respuesta aceptada
Más respuestas (1)
per isakson
el 10 de Abr. de 2021
Editada: per isakson
el 10 de Abr. de 2021
Consider the two lines
midCirc = X.^2+Y.^2 < (1/n)^2;
NmidCirc = not(midCirc);
The first line assigns a logical value (true/false) to midCirc. (As you already noticed.) The LHS of the following line expects a logical value. The input argument of the function, not(), must (IMO) be logical. (Whoever created this code intended a logical value.)
It's possible to plot logicals
>> imagesc(Tshape)
outputs 
4 comentarios
"The input argument of the function, not(), must be logical"
not(2)
not(uint32(23))
not('x')
fima v
el 10 de Abr. de 2021
per isakson
el 10 de Abr. de 2021
@Stephen Cobeldick, I added "(IMO)" to the sentence and will try to forget the use of other data types as input to not() ASAP.
per isakson
el 10 de Abr. de 2021
Editada: per isakson
el 10 de Abr. de 2021
@fima v, I just run the script of your question and the statement, imagesc(Tshape). No other code is involved.
In the same way, your script and
>> imagesc(NTshape)
>> colormap gray;
outputs 
Categorías
Más información sobre Red en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!