MATLAB: Generating A(i,j) = [i; j] matrix generation Hi, is there a clean way to generate a matrix A(i,j) = [i; j], especially without resorting to loops? Thank you so much! Best Answer You want each element of your matrix to be a two element vector?That is not a matrix, but it does sound like a cell array.C = num2cell(cumsum(ones(5),2));C = cellfun(@(x,y) [x;y],C,C.','Un',0) Related SolutionsMATLAB: Manipulation of a cell array- Cell_array = {1,[],magic(2);'stirng',[],[]}cellfun('isempty',Cell_array) MATLAB: Defining matrices to solve Ax=b using a(i,j)=-1+2max(i,j) and b(j)=sum(j to n) a(i,j) Replace your code with:summ=0; for j=1:n summ=sum(A,2)endso there is no confusion between the variable summ and the function sum. Related QuestionSelect specific values inside a cellHow p(:,j) differs from p(j,:)How can i multiply cell arraysSum up elements in cellsCell containing double arrays to cell
Best Answer