MATLAB: Matrix concatenation concatenate columns I need to create a text file with 3 columns. first two columns are of the same size, 100. The 3rd column just has one number in it. How can I do that? Best Answer With col1, col2, and col3 being column vectors:fmt = ['%f %f %f\n' repmat('%f %f\n', 1, 99)];fid = fopen('YourOutputFile.txt', 'wt');fprintf(fid, fmt, col1(1), col2(1), col3(1), [col1(2:end), col2(2:end)].');fclose(fid);Warning: the details of the fprintf() call depend upon col1 and col2 being column vectors! Related SolutionsMATLAB: How to add to txt file from certain point One way would be the following: fid_in = fopen('inFile.txt', 'r') ; fid_out = fopen('outFile.txt', 'w') ; cnt = 0 ; while ~feof(fid_in) if cnt == 7, cnt = 1 ; else cnt = cnt + 1 ; end fprintf(fid_out, '%s %d\r\n', fgetl(fid_in), cnt) ; end fclose(fid_in) ; fclose(fid_out) ; MATLAB: Converting matrix to column col1 = array(:, 1);col2 = array(:, 2);col3 = array(:, 3);col4 = array(:, 4); Related QuestionHow to write to a txt file dynamicallyImporting 2 columns using textscan (OR possibly a different/easier way?)Using FSCANF to read and extra data into matrixHow can i add a main line and main column for the tableTrying to load .dat file matlab
Best Answer