understanding "<" operator line
3 views (last 30 days)
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?
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]
Tshape= (abs(Y)<0.2/n)&(abs(X)<0.6/n) | ((Y<1.4/n)&(Y>0.2/n)&(abs(X)<0.2/n));
John D'Errico on 10 Apr 2021
In order to understand this, I'd STRONGLY recommend you do the MATLAB Onramp tutorials. Try some examples. Look at what happens! For example:
A = magic(5)
What happens if we try this?
A < 10
So we see a logical array a boolean thing, true where the corresponding element of A was less than 10, false where that condition was not true.
And that is no different from what was constructed in the code you show. TRY IT. LOOK AT THE RESULT.
More Answers (1)
per isakson on 10 Apr 2021
Edited: per isakson on 10 Apr 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