I have an equation z=x+a*n. Here a is a constant, and x varies from 0 to 10 with 1 interval. Also, n varies from 0 to 10. I have to write all these on to a dat file with first column with all values of x, then next column with values of z with n=0, next column with values of z with n=1 and so on. And also I have to put a header. The code goes like this:
clear all;clc;format long;
fprintf(fileidentifier1,'x\t z0\t z1\t z2\t z3\t z4\t z5\t z6\t z7\t z8\t z9\t z10\t \r');
fprintf(fileidentifier1,'%7.10f %7.10f %7.10f %7.10f %7.10f %7.10f %7.10f %7.10f %7.10f %7.10f %7.10f %7.10f \n',dat1');
Problem starts from putting header.
What I used to do is that I used to give the command for each of these thing manually: i.e. ‘x’, for first column, ‘z0’ for second column corresponding to n=0, ‘z1’ corresponding to n=1 and so on. As you can see that it will be a hectic of a task if that ‘n’ varies up to 100 or more. Also if you want to change the value of n from 10 to 9, the out put file will still show the correct values, but the way it is arranged will become haywire (you can try for yourself). Is there any way to write do this automatically?