what is fileID in matlab?

46 visualizaciones (últimos 30 días)
metin yilmaz
metin yilmaz el 4 de Abr. de 2020
Comentada: Mohammad Alhashash el 13 de Oct. de 2021
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 comentario
dpb
dpb el 4 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Abr. de 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 comentario
Mohammad Alhashash
Mohammad Alhashash el 13 de Oct. de 2021
Very informative. Thank you very much.

Iniciar sesión para comentar.

Categorías

Más información sobre Low-Level File I/O en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by