MATLAB Programming for Numerical Analysis by César Pérez López
Author:César Pérez López
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
As a first example we can view the contents of the file fclose.m using the command type as follows:
>> type fclose.m
%FCLOSE Close file.
% ST = FCLOSE(FID) closes the file with file identifier FID,
% which is an integer obtained from an earlier FOPEN. FCLOSE
% returns 0 if successful and -1 if not.
%
% ST = FCLOSE('all') closes all open files, except 0, 1 and 2.
%
% See also FOPEN, FREWIND, FREAD, FWRITE.
% Copyright 1984-2001 The MathWorks, Inc.
% $Revision: 5.8 $ $Date: 2001/04/15 12:02:12 $
% Built-in function.
This is equivalent to using the command type before opening the file with fopen, followed by reading its contents with fread and presenting it with the function char.
>> fid = fopen('fclose.m','r');
>> F = fread(fid);
>> s = char(F')
s =
%FCLOSE Close file.
% ST = FCLOSE(FID) closes the file with file identifier FID,
% which is an integer obtained from an earlier FOPEN. FCLOSE
% returns 0 if successful and -1 if not.
%
% ST = FCLOSE('all') closes all open files, except 0, 1 and 2.
%
% See also FOPEN, FREWIND, FREAD, FWRITE.
% Copyright 1984-2001 The MathWorks, Inc.
% $Revision: 5.8 $ $Date: 2001/04/15 12:02:12 $
% Built-in function.
In the following example, we create a binary file id4.bin which contains the 16 elements of the identity matrix of order 4 stored in 4 byte integers (64 bytes in total). First we open the file which will contain the matrix, with permission to read and write, and then write the matrix to the file with the appropriate format. Finally, we close the open file.
>> fid = fopen ('id4. bin ',' w +')
fid =
5
>> fwrite(fid,eye(4),'integer*4')
ans =
16
>> fclose (5)
ans =
0
In the previous example, when the file was opened, the system assigned ID 5 to it. After writing the matrix to the file, it was necessary to close it with the command fclose using the indicator. The answer of zero means the closure has been successful.
If we now want to see the contents of the binary file just recorded, we open it, with reading permission, by using the command fopen and read its elements with fread, in the same matrix structure and format in which it was saved.
>> fid = fopen('id4.bin','r+')
fid =
5
>> [R,count]=fread(5,[4,4],'integer*4')
R =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
count =
16
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Brazilian Economy since the Great Financial Crisis of 20072008 by Philip Arestis Carolina Troncoso Baltar & Daniela Magalhães Prates(360864)
International Integration of the Brazilian Economy by Elias C. Grivoyannis(111585)
The Art of Coaching by Elena Aguilar(53639)
Flexible Working by Dale Gemma;(23354)
How to Stop Living Paycheck to Paycheck by Avery Breyer(19834)
Thinking, Fast and Slow by Kahneman Daniel(12526)
The Acquirer's Multiple: How the Billionaire Contrarians of Deep Value Beat the Market by Tobias Carlisle(12427)
The Radium Girls by Kate Moore(12177)
The Art of Thinking Clearly by Rolf Dobelli(10710)
Hit Refresh by Satya Nadella(9247)
The Compound Effect by Darren Hardy(9145)
Tools of Titans by Timothy Ferriss(8590)
Atomic Habits: Tiny Changes, Remarkable Results by James Clear(8512)
Turbulence by E. J. Noyes(8200)
A Court of Wings and Ruin by Sarah J. Maas(8106)
Change Your Questions, Change Your Life by Marilee Adams(7928)
Nudge - Improving Decisions about Health, Wealth, and Happiness by Thaler Sunstein(7850)
How to Be a Bawse: A Guide to Conquering Life by Lilly Singh(7612)
Win Bigly by Scott Adams(7341)