MATLAB: How to arrange the data to be written on a text file (like notepad) in the specified format

writing arrays in notepad

I have an array [1 0 1] and then another array [0 -1 0]. I want to write these arrays in a text file in the specified format mentioned in the file attached .
Please provide the syntax required for the following purpose.

Best Answer

A = [1 0 1];
B = [0 -1 0];
C = repmat([A, B], 5, 1);
fmt = repmat('%.4f ', 1, size(C,1));
fmt(end:end+1) = '\n';
fid = fopen('YourFile.txt', 'wt');
fprintf(fid, fmt, C.' ); %transposing the data to be formatted is an oddity of MATLAB
fclose(fid);