MATLAB: I want to understand the meaning(Syntax) of this line. Someone please explaiin what conditions are being used and what does it exactly mean in terms of variables used

syntax

Kf(fmag<=1) = ((1-(nimage*magnification*fth(fmag<=1)).^2)

Best Answer

The result of fmag<=1 is a logical variable. The expression fth(fmag<=1) picks of those elements of fth that are at the locations of the "1" elements of the logical indexing. I.e., it picks off the fth values at the locations where fmag<=1 is true. The remaining expression on the rhs of your assignment is then evaluated for those elements, and the results are stored in the same locations (using the same logical indexing) of the Kf variable. E.g.,
>> fth = 1:10
fth =
1 2 3 4 5 6 7 8 9 10
>> Kf = zeros(size(fth))
Kf =
0 0 0 0 0 0 0 0 0 0
>> fmag = 2*rand(1,10)
fmag =
1.4121 0.0637 0.5538 0.0923 0.1943 1.6469 1.3897 0.6342 1.9004 0.0689
>> fmag<=1
ans =
1×10 logical array
0 1 1 1 1 0 0 1 0 1
>> Kf(fmag<=1) = fth(fmag<=1)
Kf =
0 2 3 4 5 0 0 8 0 10