MATLAB: How to merge rows in an array arrayconcatenateMATLABmerge Hi, I have a 399×7 double array like this: I wonder how it's possibe to create a new array with each row merged together to form an array like: Thanks! Best Answer Try this: A = randi(99, 7, 4)Amerged = str2num(sprintf([repmat('%d',1,size(A,2)) '\n'],A.'))producing (in this run): A = 53 60 11 40 10 96 93 28 41 43 19 4 11 69 27 67 12 76 79 43 78 43 49 45 29 65 77 61 Amerged = 53601140 10969328 4143194 11692767 12767943 78434945 29657761The str2double function is preferred for several reasons, however it will not work here to produce the result you want. If you want ‘Amerged’ as a character array instead, omit the str2num call: Amerged = sprintf([repmat('%d',1,size(A,2)) '\n'],A.')It is necessary to transpose the matrix (here ‘A’) to get it tyo print correctly. Related SolutionsMATLAB: How to decrease the number of points in a matrix I suggest http://www.mathworks.com/help/matlab/ref/spline.htmlx = 1 : length(psdn);x128 = linspace(x(1), x(end), 128);p128 = spline(x, psdn, x128);plot(x128, p128); MATLAB: Convert a single char array to a vector of doubles with a non-whitespace delimiter [R2017b, Windows7] a={'44.565,433.4544,34.332'};str=a{1}(:);strNum=str2double(strsplit(str.',','))Thanks to Stephen Cobeldick, another and faster approach:sscanf(a{1}, '%f,') Related QuestionSscanf /sprintf usageConvert indexed image to Text that give the exact position of the pixelHow to make string from matrixI cannot create that array in Matlab !Convert a fixed width char array into a column vector
Best Answer