understanding "<" operator line

2 ビュー (過去 30 日間)
fima v
fima v 2021 年 4 月 10 日
編集済み: per isakson 2021 年 4 月 10 日
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;
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]
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);
Tshape= (abs(Y)<0.2/n)&(abs(X)<0.6/n) | ((Y<1.4/n)&(Y>0.2/n)&(abs(X)<0.2/n));
colormap gray;


John D'Errico
John D'Errico 2021 年 4 月 10 日
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)
A = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
What happens if we try this?
A < 10
ans = 5×5 logical array
0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 1 1
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.

その他の回答 (1 件)

per isakson
per isakson 2021 年 4 月 10 日
編集済み: per isakson 2021 年 4 月 10 日
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)
  4 件のコメント
per isakson
per isakson 2021 年 4 月 10 日
編集済み: per isakson 2021 年 4 月 10 日
@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;



Community Treasure Hunt

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

Start Hunting!

Translated by