" bsxfun(@rdivide..." Explain Use in Code

13 次查看(过去 30 天)

回答(1 个)

Adam
Adam 2020-2-4
编辑:Adam 2020-2-4
rgbh_e = bsxfun(@rdivide, rgbh_e, rgbh_e(4,:));
divides rgbh_e by by the 4th row of rgbh_e, on a per row basis - i.e. each element of each row is divided by the element in the same column of the 4th row.
The best way to understand this is to create a small example and test it on command line to see what it is doing. I don't know what rgbh_e is, but for example:
>> a = rand( 4, 5 )
a =
Columns 1 through 4
0.814723686393179 0.63235924622541 0.957506835434298 0.957166948242946
0.905791937075619 0.0975404049994095 0.964888535199277 0.485375648722841
0.126986816293506 0.278498218867048 0.157613081677548 0.8002804688888
0.913375856139019 0.546881519204984 0.970592781760616 0.141886338627215
Column 5
0.421761282626275
0.915735525189067
0.792207329559554
0.959492426392903
>>
>>
>>
>> bsxfun( @rdivide, a, a(4,:) )
ans =
Columns 1 through 4
0.891991704091174 1.15630026617957 0.986517573000511 6.74601203684419
0.99169682555935 0.178357471543757 0.994122925011876 3.42087655104056
0.139030187233434 0.50924781527068 0.162388475001478 5.64029262176829
1 1 1 1
Column 5
0.439567078410234
0.954395782603168
0.825652509356184
1
Here you can see that each column is divided by the 4th row value of that column. This is implemented in recent versions by implicit expansion that does not need bsxfun. It is effectively dividing a (4,5) matrix by a (1,5) array in this case and could be done as
a ./ a(4,:)
equivalently.
As per many cases, investigating syntax on command line with simpler examples can help illuminate what is happening.
Without having looked at the code in the submission you mention I would guess this is a normalisation step that forces values to be in the correct range ( 0 - 1 ) and not get clipped off above 1.

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by