Reading and Writing data into files in Octave.

// Program read values from program and write it into file.

1. Type $ gedit hello  command  on terminal and type code in it.
a=304;
file1=fopen(‘ myfile.txt’ , ‘w’);
fprintf(file1, ‘%i’ ,a);
fclose(file1);

2. Run this file using  $octave hello

3. Open ‘ myfile.txt ‘ for output.

// Program to read values from source file and write it destination  file.

1. Type $ gedit test command  on terminal and type code in it.

file1=fopen(“sourcefile.txt”, “r”);
f=fread(file1);
file2=fopen(“destfile.txt”, “w”);
fprintf(file2 ,”%s” ,f);
fclose(file1);
fclose(file2);

2. Run this file using  $octave test.

3. Open ‘ destfile.txt ‘ for output.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s