File I/O Flashcards

1
Q

Reading values/texts from excel file

Reading everything in excel file

A

[num,text,raw] = xlsread(‘filename’)

[~ ~ everything] = xlsread(‘filename’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Opening a txt file

Unique file identifier

Types of permissions & purposes

A

Fid=fopen(filename, permission)

Fid = unique identifier

Permissions:
rt : open & read
wt: open & write, discard original content
at: open/create & write, continue from end of file
r+t : open for read & write
w+t : open/create for read & write, discard original
a+t : open/create for read & write, continue from end of file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Closing a txt file

A

Fclose(fid)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Checking if txt file is opened successfully

A

If fid 0 then file successfully opened

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Reading txt file as set of strings one line at a time

A

Fgets(fid) gets strings from txt one line at a time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Checking if end of txt file is reached

A

If ischar(fget(fid)) != 1 then end of txt file

Ischar returns 1 whenever there are still strings to read from

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Opening a binary file

Permissions

A

Fid=fopen(filename,’permission’)

Permissions:
r : open & read
w : open & write, discard old data
a : open/create & write, add to end of file
r+ : open for read & write
w+ : open/create for read & write, discard old data
a+ : open/create for read & write, add to end of file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Writing to a binary file

A

Fwrite(fid,data,’data type’)

Correct data type must be used
Eg:

If data = positive integer values, data type must be double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Reading from binary file

A

Data = fread(fid,’data type’)

Correct data type must be used to read data. If data is double, cannot use char to read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly