Question: I'm working on a function with three nested for loops that is way too slow for its intended use. The bottleneck is clearly the looping part - almost 100 % of the execution time is spent in the innermost loop.  

The function takes a 2d matrix called `rM` as input and returns a 3d matrix called `ec`:

```
rows = size(rM, 1);
cols = size(rM, 2);

%preallocate.
ec = zeros(rows+1, cols, numRiskLevels);
ec(1, :, :) = 100;

for risk = minRisk:stepRisk:maxRisk;
    for c = 1:cols,
        for r = 2:rows+1,
            ec(r, c, risk) = ec(r-1, c, risk) * (1 + risk * rM(r-1, c));
        end
    end
end

```

Any help on speeding up the for loops would be appreciated...

Answer: 
SOURCE w3c

> 
> In a block formatting context, boxes are laid out one after the other,
>  vertically, beginning at the top of a containing block. The vertical
>  distance between two sibling boxes is determined by the 'margin'
>  properties. Vertical margins between adjacent block boxes in a block
>  formatting context collapse.
> 
> 
> In a block formatting context, each box's left outer edge touches the
>  left edge of the containing block (for right-to-left formatting, right
>  edges touch). This is true even in the presence of floats (although a
>  box's content area may shrink due to the floats).
> 
> 
> 

**AND ANSWER OF YOUR QUESTION**

**`position:relative` or `float:left/right;`** makes an element to behave like an block element..`display:block`; wont have any effect if you are using `position:relative;` or `float:left/right;`
Here you can find all the values of the display property and its behaviour: <http://www.w3schools.com/cssref/pr_class_display.asp>