%sample code to read in text input using load, dlmread and textscan along %with sample code to write text using dlmwrite and fprintf clear all; %output an array to a file using dlmwrite foo = rand(10,5); %use default delimiter, row and column starting dlmwrite('sample_text.txt', foo); %or to use tab as the delimiter dlmwrite('sample_text_2.txt',foo,'delimiter','\t'); %or to use a single space as the delimiter dlmwrite('sample_text_3.txt',foo,' ',0,0); %output an array using fprintf x = 0:.1:1; foo = [x; exp(x)]; fid = fopen('sample_text_4.txt','w'); fprintf(fid,'%f \n', foo); fclose(fid); %read in a text file using load data = load('sample_text.txt'); %load infers the delimiter from the file %read in same text file using dlmread %need to specify the delimiter when using dlmread %dlmread is more flexible than load data_2 = dlmread('sample_text_2.txt', '\t', 0, 0); %read in a variable whitespace delimited file using dlmread data_3 = dlmread('sample_text_var.txt', '', 0, 0); %ignore the first three lines data_4 = dlmread('sample_header.txt', '\t', 3, 0); %read in a file using textscan fid = fopen('sample_strings.txt', 'r'); cell_data = textscan(fid,'%s',12); fclose(fid);