On 2/24/2013 3:46 PM, dhiraj wrote:
>
>> Depends what you are using for output:
>> fid=fopen(txtfile,'wt');
>> fprintf(fid,'%0.3f\n',out); % One per line
>> fclose(fid);
>> is one way to get what you want.
>
> Thanks for your reply.
>
> But when I use this, my text file loose the original data and gives me
> 112.000 101.000
> 114.000 109.000 120.000 50.000 54.000 50.000 54.000 46.000 105.000
> 110.000 99.000, these random numbers.
>
> I also tried using above code in the code, where I am actually
> generating the file, though it displays numbers in the format I want,
> but in the saved text file they are still in the format of 6.89000+002.
You're not showing something then...
>> format shorte
>> x
x =
6.9905e+01 8.0573e+01 7.9433e+01 8.0573e+01 7.9433e+01
6.9194e+01 8.3739e+01 7.9607e+01 8.3739e+01 7.9607e+01
7.0976e+01 8.1974e+01 7.8440e+01 8.1974e+01 7.8440e+01
7.5127e+01 7.9528e+01 7.7089e+01 7.9528e+01 7.7089e+01
7.7340e+01 8.0202e+01 7.7317e+01 8.0202e+01 7.7317e+01
>> fid=fopen('test.dat','wt');
>> fprintf(fid,[repmat('%8.3f',1,5) '\n'],x');
>> fid=fclose(fid);
>> type 'test.dat'
69.905 80.573 79.433 80.573 79.433
69.194 83.739 79.607 83.739 79.607
70.976 81.974 78.440 81.974 78.440
75.127 79.528 77.089 79.528 77.089
77.340 80.202 77.317 80.202 77.317
>>
--
>
>> Depends what you are using for output:
>> fid=fopen(txtfile,'wt');
>> fprintf(fid,'%0.3f\n',out); % One per line
>> fclose(fid);
>> is one way to get what you want.
>
> Thanks for your reply.
>
> But when I use this, my text file loose the original data and gives me
> 112.000 101.000
> 114.000 109.000 120.000 50.000 54.000 50.000 54.000 46.000 105.000
> 110.000 99.000, these random numbers.
>
> I also tried using above code in the code, where I am actually
> generating the file, though it displays numbers in the format I want,
> but in the saved text file they are still in the format of 6.89000+002.
You're not showing something then...
>> format shorte
>> x
x =
6.9905e+01 8.0573e+01 7.9433e+01 8.0573e+01 7.9433e+01
6.9194e+01 8.3739e+01 7.9607e+01 8.3739e+01 7.9607e+01
7.0976e+01 8.1974e+01 7.8440e+01 8.1974e+01 7.8440e+01
7.5127e+01 7.9528e+01 7.7089e+01 7.9528e+01 7.7089e+01
7.7340e+01 8.0202e+01 7.7317e+01 8.0202e+01 7.7317e+01
>> fid=fopen('test.dat','wt');
>> fprintf(fid,[repmat('%8.3f',1,5) '\n'],x');
>> fid=fclose(fid);
>> type 'test.dat'
69.905 80.573 79.433 80.573 79.433
69.194 83.739 79.607 83.739 79.607
70.976 81.974 78.440 81.974 78.440
75.127 79.528 77.089 79.528 77.089
77.340 80.202 77.317 80.202 77.317
>>
--