首先贴上Matlab本身对于fopen的介绍。
%FOPEN Open file.% FID = FOPEN(FILENAME) opens the file FILENAME for read access. FILENAME is the% name of the file to be opened.% FILENAME can be a MATLABPATH relative parti网站本地化al pathname. If the file is not found% in the current working directory, FOPEN searches for it on the MATLAB search% path. On UNIX systems, FILENAME may also start with a "~/" or a "~username/",% which FOPEN expands to the current user's home directory or the specified user's% home directory, respectively.%% FID is a scalar MATLAB integer valued double, called a file identifier. You use% FID as the first argument to other file inpu批量删除微博t/output routines, such asqq匿名 FREAD and% FCLOSE. If FOPEN百度通 cannot open the file, it returns -1.%% FID = FOPEN(FILENAME,PERMISSION) opens the file FILENAME in the mode specified by% PERMISSION:% % 'r' open file for reading% 'w' open file for writing; discard existing contents% 'a' open or create file for writing; append data to end of file% 'r+' open (do not create) file for reading and writing% 'w+' open or create file for reading and writing; discard existing% 抑郁症名人 contents% 'a+' open or create file for reading and writing; append data to end of% file % 'W' open file for writing without automatic flushing% 'A' open file for appending without automatic flushing% % FILENAME can be a MATLABPATH relative partial pathname only if the file is opened% for reading.%% You can open files in binary mode (the default) or in text mode. In binary mode,% no characters get s民爆行业ingled out for special treatment. In text mode on the PC, the% carriage return character preceding a newline character is deleted on input and% added before the newline charac北京公交车灵异事件ter on output. To open a file in text mode,% append 't' to the permission specifier, for example 'rt' and 'w+t'. (On Unix, text and% binary mode are the same, so this has no effect. On PC systems this is% critical.)%% If the file is opened in update mode ('+'), you must use an FSEEK or FREWIND% between an input command like FREAD, FSCANF, FGETS, or FGETL and an output% command like FWRITE or FPRINTF. You must also use an FSEEK or FREWIND between an% output command and an input command.%% Two file identifiers are automatically available and need not be opened. They% are FID=1 (standard output) and FID=2 (standard error).% % [FID, MESSAGE] = FOPEN(FILENAME,...) returns a system dependent error message if% the open is not successful.%% [FID, MESSAGE] = FOPEN(FILENAME,PERMISSION,MACHINEFORMA里氏替换原则T) opens the specified% file with the specified PERMISSION and treats data read using FREAD or data% written using FWRITE as having a format given by MACHINEFORMAT. MACHINEFORMAT is% one of the followi女发型师ng:%% 'native' or 'n' - local machine format - the default% 'ieee-le' or 'l' - IEEE floating point鬼头太敏感 with little-endian byte ordering% 'ieee-be' or 'b' - IEEE floating point with big-endian byte ordering% 'ieee-le.l64' or 'a' - IEEE floating point with little-endian byte ordering and% 64 bit long data type% 'ieee-be.l64' or 's' - IEEE floating point with big-endian byte ordering and 64% bit long data type.% % [FID, MESSAGE] = FOPEN(FILENAME,PERMISSION,MACHINEFORMAT,ENCODING)% opens上海新东方托福 the specified file using the specified PERMISSION and% MACHINEFORMAT. ENCODING specifies the name of a character encoding% scheme associated with the file. It must be the empty character vector% (''), empty string ("&吸毒女#34;), or a name, or alias for an encoding scheme.% Some examples are 'UTF-8', 'latin1', 'US-ASCII', and 'Shift_JIS'. For% common names and aliases, see the Web site% Character Sets. If ENCODING is%四十不惑是什么意思 unspecified, or is the empty character vector (''), or is the empty% string (""), MATLAB's default encoding scheme is used.%% [FILENAME,PERMISSION,MACHINEFORMAT,ENCODING] = FOPEN(FID) returns the filename,% permission, machine format, and character encoding values used by MATLAB when it% opened the file associated with identifier FID. MATLAB does not determine these% 育儿问题 output values by reading information from the opened file. For any of these% parameters that were not specified when the file was opened, MATLAB returns its% default value. The ENCODING is a standard character encoding scheme name that may% not be the same as the ENCODING argument used in the call to FOPEN that opened% the file. An invalid FID returns empty character vector ('') for all output arguments.%% FIDS = FOPEN('兰蔻小黑瓶眼霜all') returns a row vector containing the file identifiers for all% the files currently opened by the user (but not 1 or 2).% % The 'W' and 'A' permissions do not automatically perform a flush of the cur中国经济泡沫rent% output buffer after ouxps15tput operations.% % See also FCLOSE, FERROR, FGETL, FGETS, FPRINTF, FREAD, FSCANF, FSEEK, % FTELL, FWRITE.% FID = FOPEN(FILENAME) assumes a permission of 'r'.% Copyright 1984-2016 The MathWorks, Inc.% Built-in function.下面是作者自己对上述的翻译和理解:
FOPEN函数是用于打开文件的函数,其基本格式为 "FID = FOPEN(FILENAME)"。其通过打开某一个文件去读取路径。FILENAME是待打开文件的名字。
FILENAME可以是一个MATLAB路径的相对部分路径名。如果文件没有在当前工作目录中找到,FOPEN函数会在MATLAB搜索路径中搜寻它。在UNIX系统中,FILENAME可能以"~/"或 "~username/"开始,在这种情况下FOPEN会把路径分别扩展到当前用户的主目录或者指定用户的主目录。上文的相对路径和绝对路径是指文件层面的路径,与Java中网页的绝对路径和相对路径有所不同。其中绝对路径是从盘符开始的路径,形C:\windows\system32\cmd.exe。而相对路径是从当前路径开始的路径,假如当前路径为C:\windows,要描述上述路径,只需输入system32\cmd.exe;当然,严格的相对路径写法应为 .\system32\cmd.exe。其中,. 表示当前路径,在通道情况下可以省略,只有在特殊的情况下不能省略。
FID是一个MATLAB整数倍的标量,称为文件标识符。你可以使用FID作为其他输入/输出例程的首个参数,比如FREAD和FCLOSE。如:"FID = FOPEN(FILENAME)"中FID即是首个参数。如果FOPEN不能打开文件,FID会返回值-1。
"FID = FOPEN(FILENAME PERMISSION) "在”PERMISSION“的特定模式下打开文件“FILENAME”:
'r' 打开文件待读
'w' 打开文件待写;丢弃现有内容
'a' 打开或者新建待写文件;把数据附加在文件尾部
'r+'画图板; 打开(不新建)文件用以读与写
'w+' 打开或者新建文件用以读与写;丢弃现有内容
'a+' 打开或者新建文件用以读与写;把数据附加在文件尾部
'W' 打开文件用于写,无自动齐平
'A' 打开文件用于附录,无自动齐平
FILENAME仅在文件打开用以读时才可能作为一个MATLABPATH中的相对部分路径。
你可以用二进制模式或者文本模式打开文件,前者为默认模式。在二进制模式中,没有字符会被单独拎出来做特殊对待(get singled out一词特别形象)。而在PC电脑(典型的即我们常用的Windows系列操作系统)的文本模式中,回车符在输入时被删除,并且将其加到输出之前。在文本模式中打开文件,加't'在'permission'特定字符中,举个例子'rt'和'w+t'。(分别为'r&t'和'w+&t')。在UNIX系统中,文本模式和二进制模式时一样的,所以加't'与否并没有差别,但是在PC系统上,这是至关重要的。
如果以更新模式('+')打开文件,则必须使用FSEEK或FREWIND,在输入命令(例如FREAD,FSCANF,FGE沈阳购房TS或FGETL)与输出之间像FWRITE或FPRINTF这样的命令。 您还必须在之间使用FSEEK或FREWIND输出命令和输入命令。
-----------------------------------------------------------------
代更,明恶意差评师天补完
本文发布于:2023-06-08 16:15:07,感谢您对本站的认可!
本文链接:http://www.ranqi119.com/ge/85/258646.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |