More efficient way than a loop for this particular example
Show older comments
I code but I am never trained for it, so every once in a while I get suspicious of the possibility to do something more efficiently. Bottleneck there is the ConvertColors in-house function I use, but I think there is a better way to do the j loop. Thanks in advance.

EDIT: for some reason the editor won't indent, so see screenshot for better readibility.
referenceAchromaticGrating=zeros(screenHeight_px,spatialFrequency_px,3);
for i=0:spatialFrequency_px-1
luminance = meanLuminance+4*sin(2*pi*(1/spatialFrequency_px)*i);
RGB_array = ConvertColors('MWLRGB',[0,0,luminance],colorInfo);
for j=1:3
referenceAchromaticGrating(:,i+1,j)=RGB_array(j);
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!