I am completely new to Matlab and I also don't have Matlab – but I have been asked to convert some Matlab code to another language, which is proving a little bit tricky for me. At the moment I am stuck with the following lines which are within a loop:
d=s2(1)*ones(dim(1),1); for i=2:R, d=[d;s2(i)*ones(dim(i),1)];
s2 is a 1×2 matrix [0.1 1], dim = [3], and R is equal to 1 (the first time this code is evaluated)
My understanding is that the first line results in the 3×1 matrix
0.1 0.1 0.1
But I am confused by what happens in the for loop a) since R is 1, is this a decrementing loop (evaluated with i=2 then i=1 ?) b) I really don't get the line d=[d;s2(i)*ones(dim(i),1)] at all
Could anyone help explain this to me ?
Best Answer