MATLAB: Custom Vector – make vector x to be [1,1,….] MATLABvector Hello Experts, I want to create a vector x where all n elements are for example c. I can do this by: n=5; x=zeros(1,n);x(x==0) = 1; But how to do this in more simple way. Thanks a lot! Best Answer repmat(c,1,n)orc * ones(1,n)orc + zeros(1,n)orc(ones(1,n)) %yes, even with scalar c Related SolutionsMATLAB: Generating vectors of length N with only -1s and 1s. >> M = 5;>> N = 19;>> randi(0:1,M,N)*2-1ans = -1 1 -1 1 -1 -1 1 -1 1 -1 -1 1 -1 1 1 -1 -1 1 1 1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 1 1 -1 1 -1 1 -1 1 1 1 1 -1 1 -1 -1 -1 1 -1 1 1 1 1 -1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 1 -1 -1 -1 1 1 1 1 1 -1 -1 1 1 1 1 1 1 MATLAB: Newbie question – converting a vector into a cellarray of vectors % To cellC = repmat({X},N,1);% To matcell2mat(C)cat(1,C{:}) Related QuestionMatrix[1,1,1,1;-1,-1,-1,-1;1,1,1,1] to vector[1,1,1,1,-1,-1,-1,-1,1,1,1,1]How to output a vector instead of a scalarAdd n+1 element to a vectorVectorizationVectorization
Best Answer