I am working on producing tributary pixels input file to GAMS and I need them to be numbered in a way that distinguishes 1.1 from 1.10 and 1.100. Is there a way to print a string of characters distinguishing these differences?
To make my question clearer I have a the structure shown below. The first column is pixel number and the second has pixels flowing into this pixel. I want to print this structure into a file such that 1.1 and 1.10 are two different pixels.
1.10000000000000 01.20000000000000 01.30000000000000 01.40000000000000 01.50000000000000 01.60000000000000 0 1.70000000000000 0 1.80000000000000 0 1.90000000000000 0 1.10000000000000 02.10000000000000 [1.10000000000000,0]2.20000000000000 [1.20000000000000,0]2.30000000000000 [1.30000000000000,0]2.40000000000000 [1.40000000000000,0]2.50000000000000 [1.50000000000000,0]2.60000000000000 [1.60000000000000,0]2.70000000000000 [1.70000000000000,0]2.80000000000000 [1.80000000000000,0]2.90000000000000 [1.90000000000000,0]2.10000000000000 [1.10000000000000,0]3.10000000000000 [2.10000000000000,0]. . .10.2000000000000 [10.1000000000000,9.20000000000000,0]10.3000000000000 [10.2000000000000,9.30000000000000,0]10.4000000000000 [10.3000000000000,9.40000000000000,0]10.5000000000000 [10.4000000000000,9.50000000000000,0]10.6000000000000 [10.5000000000000,9.60000000000000,0]10.7000000000000 [10.6000000000000,9.70000000000000,0]10.8000000000000 [10.7000000000000,9.80000000000000,0]10.9000000000000 [10.8000000000000,9.90000000000000,0]10.1000000000000 [10.9000000000000,9.10000000000000,0]
I used this code:
fid = fopen('UBNTrib_mariam1.txt', 'w');fprintf('Neighboring Tribs List\n');fprintf('pixel,Num tribs, Tributaries');for k=1:size(tribarray,2)num2str(tribarray(k).pixel),num2str(tribarray(k).trib));fprintf(fid, '%s, %s, %s\n', num2str(tribarray(k).pixel), num2str(size(tribarray(k).trib,2)));for j = 1:size(tribarray(k).trib,2)fprintf(fid, '%s,', num2str(tribarray(k).trib(j)));endfprintf(fid, '\n');endfclose(fid);
% view the contents of the file type UBNTrib_mariam1.txt;
'done'
However the output is: Neighboring Tribs List pixel,Num tribs, Tributaries
1.1, 1, 0,
1.2, 1, 0,
1.3, 1, 0,
. . .
10.1, 3, 10.9,9.1,0,
so the last line for instance should be : 10.10 , 3 , 10.9, 9.10,0
Thanks a lot, Mariam
Best Answer