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

1 次查看(过去 30 天)
Kf(fmag<=1) = ((1-(nimage*magnification*fth(fmag<=1)).^2)

采纳的回答

James Tursa
James Tursa 2018-1-22
编辑:James Tursa 2018-1-22
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by