I just want to create an array like this:
a = [1 1 2 2 3 3 4 4 5 5 6 6 ....] %% or something like this a = [1 1 1 .. ktimes 2 2 2 ... ktimes .....]
Can this be done with one line of code in MATLAB? I believe that there are several answers. No cycles please.
With reshape and repmat
reshape
repmat
reshape(repmat([1:6],k,1),1,[])
With bsxfun -
bsxfun
reshape(bsxfun(@plus,[1:6],zeros(k,1)),1,[])
On popular request with floor -
floor
floor(1:1/k:6+(k-1)/k)
Let n = 6; and k = 2; . Here are a few alternatives:
n = 6;
k = 2;
kron(1:n,ones(1,k))
or
ceil(1/k:1/k:n)
double(uint64(1:n*k)/k)
Source: https://habr.com/ru/post/1213261/More articles:C ++ boost :: asio :: async_write send problems - c ++Suppress specific Doxygen warnings - cChat diagram MongoDB - javascriptHow to implement Spring Security on my Spring 4.0 RestFul web service? - springParsing and sorting Windows Heap Chunk partition titles - heapcontradiction between! heap -x -v and! heap -flt s - heapHow to use a macro variable in R? (Similar to% LET in SAS) - rHeap process segments and their need - heapBuilding PMF neatly in python - pythonSolrj with Solr Suggestester - javaAll Articles