MATLAB: How can Write a function that combines two lists by alternatingly taking elements, e.g. [23,11,70], [1,2,3] → [23,1,11,2,70,3]. alternatingly combines function C= concat(L1,L2) T=[L1(1),L2(1)]; for i=2:length(L1) T(end+1)=L1(i) T(end+1)=L2(i); end C=T; end Best Answer Using the reshape function:A = [23,11,70];B = [1,2,3];Out = reshape([A; B], 1, [])Out = 23 1 11 2 70 3 Related SolutionsMATLAB: Write data on to Excel If I understood correctly:xlswrite(somefile, reshape([M, nan(size(M, 1), 1, size(M, 3))], 6, []), '', 'E1')basically pad your 3D matrix with a column of NaNs. NaNs result in empty cells in the output spreadsheet. MATLAB: Multiplication question in 3 dim F = (X.*Y) .* reshape(L, 1, 1, []) Related QuestionChanging point coordinates in a file to closest ones in another fileIndexing with two matricesA simpler way of doing a nested loop
Best Answer