help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: write text in file txt


From: Nicholas Jankowski
Subject: Re: write text in file txt
Date: Mon, 1 Jul 2019 18:07:34 -0400

> i want see this output:
>
>
> 0  0  0  1710  16
> 0  0  0  2870  16
> 0  0  0  1650  16
>

Here is what I get:
octave:1> A = "0 0 0 1710 16"
A = 0 0 0 1710 16
octave:2> B = "0 0 0 2870 16"
B = 0 0 0 2870 16
octave:3> C = "0 0 0 1650 16"
C = 0 0 0 1650 16
octave:5> save gnuu.txt A -append
octave:6> save gnuu.txt B -append
octave:7> save gnuu.txt C -append

the text file contains:

--------------------------------------
# Created by Octave 5.1.0, Mon Jul 01 17:48:32 2019 GMT <unknown@hostname>
# name: A
# type: string
# elements: 1
# length: 13
0 0 0 1710 16

# name: B
# type: string
# elements: 1
# length: 13
0 0 0 2870 16

# name: C
# type: string
# elements: 1
# length: 13
0 0 0 1650 16

--------------------------

the save command saves the variable information so that a load command can load them back into memory.  

it looks like you're using the -ascii option, which is saving the ascii charater values as a single precision matrix. I can recreate that by typing:

save -ascii "gnuu2.txt" A B C

---------------------------------
 4.80000000e+01 3.20000000e+01 4.80000000e+01 3.20000000e+01 4.80000000e+01 3.20000000e+01 4.90000000e+01 5.50000000e+01 4.90000000e+01 4.80000000e+01 3.20000000e+01 4.90000000e+01 5.40000000e+01
 4.80000000e+01 3.20000000e+01 4.80000000e+01 3.20000000e+01 4.80000000e+01 3.20000000e+01 5.00000000e+01 5.60000000e+01 5.50000000e+01 4.80000000e+01 3.20000000e+01 4.90000000e+01 5.40000000e+01
 4.80000000e+01 3.20000000e+01 4.80000000e+01 3.20000000e+01 4.80000000e+01 3.20000000e+01 4.90000000e+01 5.40000000e+01 5.30000000e+01 4.80000000e+01 3.20000000e+01 4.90000000e+01 5.40000000e+01
---------------------------------

to get your desired output, you can first convert your strings to numbers and then use the ascii output option:

>> D = str2num([A;B;C])
D =
      0      0      0   1710     16
      0      0      0   2870     16
      0      0      0   1650     16
octave:17> save -ascii "gnuu2.txt" D

---------------------------------
 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.71000000e+03 1.60000000e+01
 0.00000000e+00 0.00000000e+00 0.00000000e+00 2.87000000e+03 1.60000000e+01
 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.65000000e+03 1.60000000e+01
---------------------------------

if you want them written as integers, you might need to use some of the other file output commands. eg, 

> dlmwrite("gnuu3.txt",D," ")
------------------
0 0 0 1710 16
0 0 0 2870 16
0 0 0 1650 16
-------------------










reply via email to

[Prev in Thread] Current Thread [Next in Thread]