MATLAB: What does x= [ones(1,2) 2 ones(1,1) 2 ones(1,2) 1] do arrayMATLAB please explain the X= [ones(1,2) 2 ones(1,1) 2 ones(1,2) 1]; line of code. I understand that it is creating 1 by 2 array of ones. But what is the significance of 2 ones(1,1) and so on. Best Answer It depends on the requirement of what array you want. If you see that line generates: [1 1 2 1 2 1 1 1]The array has 2 in 3rd, 4th position. So 2 is used. The same can also be generated using: X = ones(1,8) ; X([3 5]) = 2 Related SolutionsMATLAB: Si=2*(round(rand(1,sbit))-1/2); a=rand% b=rand(a) % the result is 0 or 1%If b=12*(1-1/2)=1%If b=02*(0-1/2)=-1 MATLAB: How to use matrix elements as indices to access elements of another matrix Values(:,:,1) = [0 0 1 2 2 2 1 1 2 1 0 0 1 1 2 1 2 1 2 2]Values(:,:,2) = [1 0 1 2 2 0 2 1 1 1 2 0 1 0 2 1 1 2 2 0]Values(:,:,3) = [1 2 1 0 2 0 2 1 2 0 1 2 0 0 2 1 1 1 2 2]Id = [1 2 1 1 1 2 2 2 3 1 3 1 1 2 3 1 2 2 3 3][n,m]=size(Id)[x,y]=ndgrid(1:n,1:m)idl=sub2ind(size(Values),x,y,Id)Result=Values(idl) Related Question1.1 + 0.1 == 1.2 returns falseDelete values in a vector based on another vector
Best Answer