inserting headline in matlab exporting file -


i have matrix (input) , want export text file (output), therefore, using following code in matlab:

save('out.txt', 'input', '-ascii'); 

my question how can insert example 3 lines (as follow) header? don't want open output.txt file in program, because size of output.txt large , non of available softwar can open it. therefore, want directly in matlab.

these data set are... created 2013 

i think cannot using save function. quick, can see 2 options might useful.

first. create file header , use save -append options:

input = rand(5); header = ['these data set created 2013'];  fileid = fopen('out.txt','w'); fprintf(fileid,'%s\n', header); fclose(fileid);  save('out.txt', 'input', '-ascii', '-append');  

second. instead of using save, manually use fprintf write everything:

input = rand(5); header = ['these data set created 2013'];  fileid = fopen('out.txt','w'); fprintf(fileid,'%s\n', header); fprintf(fileid,[repmat('%f ', [1, size(input, 2)]),'\n'], input); fclose(fileid); 

if u want multi-line header, u can follows:

header = ['these data set ...\nit created by\n2013'];   fileid = fopen('out.txt','w'); fprintf(fileid, [header, '\n']); fprintf(fileid,[repmat('%f ', [1, size(input, 2)]),'\n'], input); fclose(fileid); 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -