2023 2024 EduVark > Education Discussion > General Discussion


  #1  
September 29th, 2016, 03:32 PM
Unregistered
Guest User
 
Open .mat file in freemat

Hii sir, I am MCA Student I wants to know About the FOPEN Function please provide A Code for Executing the FOPEN Function ?
Similar Threads
Thread
CAPF Trace File
CMAT Pdf File
Civil Service Exam Where to File
Where IAF file
Asc File
How to Open Matlab Mat File
IRDA File Complaint
File RTI Ahmedabad Municipal Corporation
How to file RTI form of PTU
MBA PDF File
AIEEE PDF file
GPAT Syllabus PDF File
DCR File Player
SCRA PDF File
PDF File MBA Project

  #2  
September 29th, 2016, 04:11 PM
Super Moderator
 
Join Date: Mar 2012
Re: Open .mat file in freemat

FOPEN File Open Function

FOPEN is A Function Which Opens a file and returns a handle which can be used for subsequent file manipulations.

The general syntax for its use is

fp = fopen(fname,mode,byteorder)

Here fname is a string containing the name of the file to be opened.

mode is the mode string for the file open command.

The first character of the mode string is one of the following:


Modes of the FOPEN Function String

'r' Open file for reading. The file pointer is placed at the beginning of the file. The file can be read from, but not written to.

'r+' Open for reading and writing. The file pointer is placed at the beginning of the file. The file can be read from and written to, but must exist at the outset.

'w' Open file for writing. If the file already exists, it is truncated to zero length. Otherwise, a new file is created. The file pointer is placed at the beginning of the file.

'w+' Open for reading and writing. The file is created if it does not exist, otherwise it is truncated to zero length. The file pointer placed at the beginning of the file.

'a' Open for appending (writing at end of file). The file is created if it does not exist. The file pointer is placed at the end of the file.


'a+' Open for reading and appending (writing at end of file). The file is created if it does not exist. The file pointer is placed at the end of the file.


Example of the FOPEN Function


Examples
Here are some examples of how to use fopen. First, we create a new file, which we want to be little-endian, regardless of the type of the machine. We also use the fwrite function to write some floating point data to the file.

--> fp = fopen('test.dat','w','ieee-le')

fp =
8

--> fwrite(fp,float([1.2,4.3,2.1]))

ans =
12

--> fclose(fp)

Next, we open the file and read the data back

--> fp = fopen('test.dat','r','ieee-le')

fp =
8

--> fread(fp,[1,3],'float')

ans =
1.2000 4.3000 2.1000

--> fclose(fp)

Now, we re-open the file in append mode and add two additional floats to the file.

--> fp = fopen('test.dat','a+','le')

fp =
8

--> fwrite(fp,float([pi,e]))

ans =
8

--> fclose(fp)

Finally, we read all 5 float values from the file

--> fp = fopen('test.dat','r','ieee-le')

fp =
8

--> fread(fp,[1,5],'float')

ans =
1.2000 4.3000 2.1000 3.1416 2.7183

--> fclose(fp)


Quick Reply
Your Username: Click here to log in

Message:
Options



All times are GMT +5. The time now is 05:09 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.6.0

1 2 3 4 5 6 7 8