what is fileID in matlab?

33 vues (au cours des 30 derniers jours)
metin yilmaz
metin yilmaz le 4 Avr 2020
I have no experience in programming.
Would you please explain what "fileID" is in general and for specifically in Matlab? What is it used for in general and specifically in matlab?
Thank you.
  1 commentaire
dpb
dpb le 4 Avr 2020
Typically that would be a variable used as a file handle -- the return value from a call to fopen and subsequently used in fread, fscanf, textscan and other lower-level i/o functions for input or alternatively, fwrite or fprintf for output.
See documentation for fopen and friends...
Of course, somebody could have just used the variable name for anything in the world so context would be the determining factor, but most generally the above is what would expect and find most common.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 4 Avr 2020
Computer languages, and operating systems, need to maintain information about every file that the program is using, such as which file it is, which encoding it is using, whether it a binary or text file, whether it is open or not, and what the current position is in the file.
I/O operations such as fread() and fprintf() need to specify which file is being referred to, in order for the I/O operation to succeed.
You could propose to pass the data structure (of information about the file) around everywhere, but if you did that then different routines would have different information about the state of the file (such as what the current position is inside the file.) Therefore, programming languages do not pass around the data structure itself, and instead pass around information about where to find the data structure.
When a memory pointer to a data structure (a "handle" in MATLAB terms) is passed around, then that situation is referred to as passing a "file pointer". This is the approach used in C for functions such as fgets(). However the term "file pointer" is ambiguous as it can also be used to refer to the current position within the file, so C tends to refer intead to FILE* which in C means a pointer to a FILE structure.
A different approach is to instead have an array of data structures, each one representing a possible file, and to pass around the index into the array. This is referred to as a "file identifier", and historically is a signed integer, with negative numbers indicating failure. Traditionally, a file identifier that was the integer 3 would refer to the fourth entry in the array of information about files (traditionally numbering starts at 0.) Traditionally, identifier 0 is used for "standard input", identifier 1 is used for "standard output", and identifier 2 is used for "standard error" (a location to send error messages to.) That leaves 3 as the lowest number for user-opened files, and you may have noticed that 3 is the value that you get back most often from fopen()
  1 commentaire
Mohammad Alhashash
Mohammad Alhashash le 13 Oct 2021
Very informative. Thank you very much.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by