Matlab programming code understanding -


i have come across matlab code unable understand. if knows code means me in regard.

lambda(:,1) = [randi([1,4], 1,4), randi([1,30],1)*rand]; 

i know randi return random integer between [min, max]. know, lambda receive? a row values, a column values or only scalar value?

well.. run code , see happens:

[randi([1,4], 1,4), randi([1,30],1)*rand] ans =     4.0000    2.0000    4.0000    1.0000   11.9046 

so answer be: row vector 5 entries.

but let's @ more detailed: randi([1,4], 1,4) create row vector of size 1 x 4, containing random integers between [min,max], i.e. between 1 , 4. second part creates 1 integer in range [1,30] , multiplies random number interval (0,1). [x,y] concatenate 2 numbers or vectors. leads row vector of size 1 x 5, saw in beginning.

in end assign lambda(:,1). in matlab first index rows , second columns, select first column of lambda. trying assign 1 x 5 row vector 5 x 1 column vector. luckily matlab smart enough handle that, snippet work anyways. nicer , more clear solution, if created column vector instead of row vector in first place. be

lambda(:,1) = [randi([1,4], 4,1); randi([1,30],1)*rand]; 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -