MATLAB: How to construct this vector without loop MATLABvector Hi, everyone: I was wondering, is it possible to construct following vector without for loop? A=[1 2 3 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 …..] or equivalently A=[1:(3*1), 1:(3*2), 1:(3*3), 1:(3*4), …., 1:(3*n)] Many thanks! Best Answer Here is flexible version not using cell2mat:n = 4 ; % user specifiedV = 3 ; % as in the example -> [1:V 1:2*V ... 1:n*V]ix = V*[1:n]A = ones(1,sum(ix))ix =ix(1:n-1)A(cumsum(ix)+1)=-ix+1A = cumsum(A) % result Related SolutionsMATLAB: Operations between every 2 different elements in a cell Maybe you mean:index = nchoosek(1:4, 2);for k = 1:size(index, 1) operation(ur{index(k, 1), 3}, ur{index(k, 1), 3});end MATLAB: Construct Power of Matrix without for loop ExampleA=magic(2);N=3;B=cell2mat(arrayfun(@(x) A^x,1:N,'un',0)) Related QuestionHow to vectorize double sumFind a vector in a big vectorHOW CAN I PLOT THE FOLLOWING POINTS USING SURFACE PLOTHow to repeat rows of matrix
Best Answer