MATLAB: Split Number into digits adding up to it. splitsum I need to split a number into smaller integers that add up to it. So 4 -> [0,4],[1,3],[2,2],[3,1],[4,0] 6 -> [0,6],[1,5],[2,4],[3,3]… I know this can be done with for loops but wanted to see if there is another way. Best Answer What aboutf = @(n) [0:n; n:-1:0].';Result>> f(4)ans = 0 4 1 3 2 2 3 1 4 0>> f(6)ans = 0 6 1 5 2 4 3 3 4 2 5 1 6 0 Related SolutionsMATLAB: HOW CAN I PLOT THE FOLLOWING POINTS USING SURFACE PLOT a={[0, 0, 0.3], [1/4, 0, 1.1], [1/2, 0, 2], [3/4, 0, 1.5], [1, 0, 2]...[0, 1/3, 0.3], [1/4, 1/3, 2], [1/2, 1/3, 1.8], [3/4, 1/3, 1.5], [1, 1/3, 2]...[0, 2/3, 3], [1/4, 2/3, 2], [1/2, 2/3, 3], [3/4, 2/3, 3.3], [1, 2/3, 3]...[0, 1, 2], [1/4, 1, 3], [1/2, 1, 2.5], [3/4, 1, 4], [1, 1, 4.5]}a=cell2mat(a')x=reshape(a(:,1),5,[])y=reshape(a(:,2),5,[])z=reshape(a(:,3),5,[])mesh(x,y,z)%orsurf(x,y,z) MATLAB: From a=[1 2 3 4] to b=[1 1 2 2 3 3 4 4] b = repelem(a,2) Related QuestionExtract matrix from matrix with the values of the axis
Best Answer